In Python, I want to count the number of lines in an xh-2.txt .
import subprocess subprocess.call("wc -l xh-2.txt",shell=True)
But this gives me exit status, not the result of the team.
I know that print os.popen("wc -l xh-2.txt|cut -d' ' -f1").read() will do the job, but popen will depreciate and why use read ()?
What is the best way to invoke a system command inside Python and get its output result, rather than exit state?
source share