我有兩個半依賴的python腳本。 ScriptA應該運行,即使ScriptB不是。相反,ScriptB只能在ScriptA運行時繼續。使用shell子進程來確定第二個腳本是否仍在運行
我的想法是像
proc = subprocess.Popen(["ps aux | grep scriptA.py | wc -l"],shell=True,STDOUT=X)
並以某種方式檢查結果是2
(因爲這將是1
,由於grep的)。
我收到2
,當在python控制檯中測試,但我努力保存標準輸出。試圖使用stdout=variable
但失敗。當我使用的是string
子進程失敗(與c2pwrite = stdout.fileno()
),其使用int
當它始終爲0。
對所有腳本使用pid文件:http://unix.stackexchange.com/questions/12815/what-are-pid-and-lock-files-for – Minos 2014-12-03 10:11:22