1

I'm trying to exec python script using PHP, but python seems to dont work when exec by php.

I tryied this code to test

$cmdResult = shell_exec("ls & /usr/local/bin/python2.7 --version & echo done");

Returned:

done
LICENSE
example.py

When I exec it on console (shell):

[root@local folder]# /usr/local/bin/python2.7 --version
Python 2.7.6

Anyone have any idea whats the problem?

Aditional info:

[root@local folder]# ls -all /usr/local/bin/py*
-rwxr-xr-x 1 root apache      84 Jul 21 21:53 /usr/local/bin/pydoc
lrwxrwxrwx 1 root root        24 Jul 21 21:43 /usr/local/bin/python -> /usr/local/bin/python2.7
-rwxrwxrwx 1 root apache 4669791 Jul 21 21:53 /usr/local/bin/python2.7
-rwxr-xr-x 1 root apache    1674 Jul 21 21:53 /usr/local/bin/python2.7-config
10
  • Use passthru() instead of shell_exec() Commented Jul 25, 2016 at 20:03
  • didnt returned Python version aswell. passthru() Commented Jul 25, 2016 at 20:05
  • use && instead of & Commented Jul 25, 2016 at 20:34
  • using && instead of & didnt also not returned python version. result: example.py LICENSE done (only changed the order from result) Commented Jul 25, 2016 at 20:37
  • did you replaced both &? Commented Jul 25, 2016 at 20:38

1 Answer 1

1

In your shell command try using && like so:

ls && /usr/local/bin/python2.7 --version && echo done

so your code would read

$cmdResult = shell_exec("ls && /usr/local/bin/python2.7 --version && echo done");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.