Can I simply execute Python program using PHP like this? (in a browser)
exec("python myProgram /Applications/MAMP/htdocs/somefile.xml");
or like this:
exec("/path/to/python path/to/myProgram /Applications/MAMP/htdocs/somefile.xml");
Is any of this method correct?
If not, what should be the right way to do it?
Thanks
I would prefer using
proc_open()as suggested by mvds as you can’t write to STDIN nor read from STDOUT withexec()/shell_exec(), as well as providing your own set of environment variable –$_ENV.A sample snippet extracted from my code:
Read more: http://php.net/manual/en/function.proc-open.php