I\'m trying to run shell command like this from php:
ls -a | grep mydir
But php only uses the first command. Is there any way to force php to p
The answer:
PLEASE avoid extensive solutions for such trivial things. Here it is the solution: *as it would be so long to do it in php, then do it in python (using subprocess.Popen in python would take three lines), and then call python's script from php.
It's about seven lines in the end, and the problem ends up solved:
Script in python, we'll call it pyshellforphp.py
:
import subprocess
import sys
comando = sys.argv[1]
obj = subprocess.Popen(comando, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
output, err = obj.communicate()
print output
how to call the python script from php:
system("pyshellforphp.py "ls | grep something");