1 year ago
#345561
Lucas F
Python execution with PHP on ubuntu works in shell, not in PHP
I am trying to create a python script that send a poll + message througout a messaging app, but my script doesn't seems to work.
First of all take into account that this command works from the SSH shell of the server:
/usr/bin/python /home/bitnami/stack/wordpress/polls-push.py
And correctly send my message to the service. (classic command line execution).
But once I call it with PHP, it does not work anymore:
$cmd = escapeshellcmd( '/usr/bin/python /home/bitnami/stack/wordpress/polls-push.py' );
echo '['.shell_exec( $cmd ).']';
I tried as well with and without escapeshellcmd
and with both shell_exec
and exec
but nothing is working as expected. Same with absolute or relative path.
Here are my file rights:
$ ls -l polls-push.py
-rwxrwxrwx 1 bitnami bitnami 3749 Mar 28 15:35 polls-push.py
And my polls-push.py
file starts with:
#!/usr/bin/env python
# coding: utf-8
With error message:
echo '<div>exec + escape + err message</div>';
$cmd = escapeshellcmd( '/usr/bin/python /home/bitnami/stack/wordpress/polls-push.py 2>&1' );
echo '['.shell_exec( $cmd ).']';
Displays: []
Edit: To get the error:
$arg = escapeshellarg( '/home/bitnami/stack/wordpress/polls-push.py' );
$exit = '2>&1';
$cmd = '/usr/bin/python '.$arg.' '.$exit;
echo shell_exec( $cmd );
python
php
shell-exec
0 Answers
Your Answer