Reputation: 19
when I try to run an external program on CMD using the PHP CLI, it opens it with my text editor when I expect it to return the program output
my PHP CLI that I run on CMD:
php -r shell_exec('filename.py');
my python file simply has:
print('hello world')
after checking this question and its answer, the result didnt change
I have windows10 64bits if that matters
thank you
Upvotes: 0
Views: 58
Reputation: 2433
In Windows, the shell_exec
with a file name will execute the default application configured to handle that file type.
This is equivalent to double-clicking that file in windows explorer.
To change the default file handling, you can right-click a file, select Open with
and specify to Always use this app
. If you choose the python interpreter, this will lead to the expected result in PHP. Although, it might not be what you expected when you click on the file to open it.
The alternative is to use the full command line including the path to the python.exe file as @Magnus Eriksson pointed ou in the comments.
Upvotes: 1