Normally I use:
os.popen("du folder >> 1.txt ").read()
It was working fine.
But when I wanted to grab the subprocess id, it returns the empty value.
os.popen("du folder >> 1.txt &").read() # Notice the & symbol
Does anyone know why and how to get the PID?
You'll want to use the subprocess module.
# Can't use shell=True if you want the pid of `du`, not the
# shell, so we have to do the redirection to file ourselves
proc = subprocess.Popen("/usr/bin/du folder", stdout=file("1.txt", "ab"))
print "PID:", proc.pid
print "Return code:", proc.wait()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With