我有两个半依赖的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