Pycharm wont run .py file when executed by a .PHP file

Hi everybody,

I am building a machine as a hobby which involves coding. To let you know from the start I am not an expert in any programming language.

Basic idea: Webbutton is pressed with activates a servo. After each activation the servo turn a different direction. 

I am using the following structure to achieve this: 

HTML Buttom: 

<form action="p1.php" method="get">
<input type="submit" name="1" value="Servo1">
</form>

PHP file: 

$command = escapeshellcmd('/Users/OS/Desktop/PHP TESTER/s1.py');
$output = shell_exec($command);
echo $output;
header('Location: tester.html ');

PYTHON file: 

#!/usr/bin/python
import serial
import time
import sys

ser = serial.Serial('/COM3', 9600)

try:
fh = open("dataAB.txt", "r+")
except FileNotFoundError:
print("data file not found creating a new one: last operation set to'w'")
fh = open("dataAB.txt", "w")
fh.write("A")
fh.close()
fh = open("dataAB.txt", "r+")

last_operation = fh.readline()

if last_operation == 'A':
fh = open("dataAB.txt", "w")
fh.write("B")
time.sleep(3)
ser.write(b'B')
time.sleep(5)


elif last_operation == 'B':
fh = open("dataAB.txt", "w")
fh.write("A")
time.sleep(3)
ser.write(b'A')
time.sleep(5)

else:
print("data file has been messed with, falling back to original setting: last opperation set to 'w', run program again")
fh = open("dataAB.txt", "w")
fh.write("A")

sys.exit()

Now I created these files on my laptop using pycharm, and everything works fine. Webbutton is pressed >> PHP file is activated >> Pycharm runs the .py script in the background >> Servo moves (and can be repeated). 

I am using a different computer now for the project I am working on. When I transferred the file to the other computer I encounter a PROBLEM:

When the .php file is activated it recognized the .py and starts PyCharm (if it is not running already) but does not open it (PyCharm Icon is blinking orange on the taskbar). As shown on the screenshot below. 

The .py script is not activated/run and the servo is not moving.

I have tried many different things but I am not finding any solutions for this problem. 

Thank you for your time and effort. 

 

0

Please sign in to leave a comment.