2

I have a python file on my raspberrypi that makes an led blink, which i made executable with chmod +x file.py so that in terminal i can run ./file.py and the led blinks. I then wrote a php file (in the same directory as file.py)

code

<html>
<head>

    <title id = "my_title"> my page </title>

</head>
<body>

    <button id="my-button"> Button </button>

</body>
</html>

I want to run file.py when i push the button, maybe with system ("./file.py");. But when i putt this directly in the code

<?php
    system ("./file.py");
?>

it doesnt do anything except print on the site Number of arguments: 1 arguments. Argument List: ['./file.py'] (ls works as expected). How might i go about running file.py when Button is pushed, and why won't system run ./file.py. Thanks

  • 1
    Try using the complete path to the file. Is file.py executable? Can you edit your question and include the contents of file.py and an ls -la of the directory it is in. – Steve Robillard Jan 11 '17 at 2:46
1

Does your file.py start with a correct shebang line? (i.e. #!/usr/bin/python)? That's how the system decides which interpreter to use when you're trying to execute the script.

In any case, you can just specify the interpreter in the system command itself:

<?php
    system ("python ./file.py");
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy