I need to store the result of a shell command that I executed in a variable, but I couldn’t get it working. I tried like:
import os
call = os.system("cat syscall_list.txt | grep f89e7000 | awk '{print $2}'")
print call
But it prints the result in terminal and prints the value of call as zero, possibly indicating as success. How to get the result stored in a variable?
Use the
subprocessmodule instead:Edit: this is new in Python 2.7. In earlier versions this should work (with the command rewritten as shown below):
As a side note, you can rewrite
To
And you can even replace the entire statement with a single
awkscript:Leading to: