I'm just learning python (using 2.7.8) and i'm trying to figure out what is the best way to evaluate the output of a system command. I've read to use
subprocess. For example, I need to run this
IF statment and evaluate for anything
> 0, then process it.
Example of unix command:
cat dump_cars_tbl.out | grep -i hummer | wc -l' (in this case it should return a value of
In python, I've tested this, but my results is wrong. It should return a
>>> import subprocess >>> mycat=subprocess.call('cat dump_cars_tbl.out | grep -i hummer | wc -l', shell=True) 1 >>> if mycat > 0: ... print('Yes') ... else: ... print('No') ... No
What am I doing wrong? Also, should i use
subprocess.call for something like this? I also need to make sure that the command
mycat doesn't return an error too.
If you have a better example how to execute and evaulate a command like this, please show me. Thank you.