Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By makhand on
I seem to be able to run a variety of
echo exec("ls -l");
echo exec("pwd");
or
$uptime=shell_exec("uptime");
and i am able to output these results in a block or a blog post.
When i try to execute a python script, like say 'exec("python2.3 myprogram.py")', i dont seem to be able to get anywhere. Am i doing something wrong? is there a permisions thing? My python script outputs an image into a writable directory. This doesnt happen.
thanks for the help
Comments
is your program executable?
you could try `command`
more to the point the first line of myprogram.py should be !#/path/to/python, so you can avoid calling 'exec("python2.3 myprogram.py")'. It is possible that php is executing python2.3 as a command, and that results in an interactive shell.
I'd also check permissions, does the webserver have permission to execute your script, and output to whatever directory that you have set?
Just some quick ideas...
Thanks for the comments. I'm
Thanks for the comments.
I'm sorry, I dont know what you meant by "you could try `command`". I couldnt seem to find anything about it.
I did try the !#/path/to/python (actually putting the path in), but with little improvement. Both the script and the directory to which it is writing has all (read/write/execute) permissions enabled.
Still no progress. The only saving grace at this point is that i may be able to run the script asynchronously (in its own loop), without much loss to the webpage. If anyone else would like to chime in, i'd appreciate it.
backtick operator
sorry about not being clear , i meant the "backtick operator".
http://www.php.net/manual/en/language.operators.execution.php. I wish i could help more.
backtick operator
sorry about not being clear , i meant the "backtick operator".
http://www.php.net/manual/en/language.operators.execution.php. I wish i could help more.
Dunno about python
But I've put PHP through some loops with commandline OK before now.
For testing I'd start with
And see if there are any errors coming out (note piping like that won't work under Windows - for that you make a BAT file - where piping WILL work, then just call that)
Don't rely on the ENV and PATH being the same for your shell and the server process - hence use /full/path/... until you are sure the right files are being found.
Your server and/or PHP error log may also have some help.
Unless the PHP page is totally stalling, I don't think it's getting trapped in an interactive prompt.
.dan.
http://www.coders.co.nz/
.dan. is the New Zealand Drupal Developer working on Government Web Standards