As @mdurant said in a comment: The subprocess
module is preffered over os.system()
. You can get the output of the external program directly into your program without an intermediate file, and also there is no extra shell process started between your program and the external program.
Example in an IPython session:
In [5]: subprocess.check_output(['du', '-sk', 'tmp'])
Out[5]: '101160\ttmp\n'
In [6]: subprocess.check_output(['du', '-sk', 'tmp']).split('\t', 1)
Out[6]: ['101160', 'tmp\n']
In [7]: subprocess.check_output(['du', '-sk', 'tmp']).split('\t', 1)[0]
Out[7]: '101160'
In [8]: int(subprocess.check_output(['du', '-sk', 'tmp']).split('\t', 1)[0])
Out[8]: 101160