python - Grabbing the output from the terminal -
i need run proccess in terminal grab output it.
import subprocess subprocess.check_output(["my_util", "some_file.txt", " | grep 'some data1' | awk '{print $2}'"]) #or subprocess.check_output(["my_util", "full_path/some_file.txt", "| grep 'some data1'", "| awk '{print $2}'"])
and nothing happens in repl, while running in terminal manually gives me proper output.
update:
the output sublime text:
my_util fail formats: can't open input pipe `| grep 'sample data1'': premature eof my_util fail formats: can't open input pipe `| awk '{print $2}'': premature eof traceback (most recent call last): file "/test1.py", line 4, in <module> "| grep 'sample data1'", "| awk '{print $2}'"]) file "/usr/lib/python2.7/subprocess.py", line 544, in check_output raise calledprocesserror(retcode, cmd, output=output) subprocess.calledprocesserror: command '["my_util", "full_path/some_file.txt", "| grep 'some data1'", "| awk '{print $2}'"]' returned non-zero exit status 2
os.system can used instead of subprocess
import os os.system("my_util some_file.txt | grep 'some data1' | awk '{print $2}'" )
Comments
Post a Comment