通常、私は使用します:
os.popen("du folder >> 1.txt ").read()
正常に動作していました。
しかし、サブプロセス ID を取得しようとすると、空の値が返されます。
os.popen("du folder >> 1.txt &").read() # Notice the & symbol
PIDを取得する理由と方法を知っている人はいますか?
subprocess
モジュールを使用する必要があります。
# 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()