0

通常、私は使用します:

os.popen("du folder >> 1.txt ").read()

正常に動作していました。
しかし、サブプロセス ID を取得しようとすると、空の値が返されます。

os.popen("du folder >> 1.txt &").read() # Notice the & symbol

PIDを取得する理由と方法を知っている人はいますか?

4

2 に答える 2

8

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()
于 2013-10-03T06:30:29.117 に答える