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