0
我有我在后台运行的命令的代码片段:如何使用pexpect.spawn命令在后台运行?
from sys import stdout,exit
import pexpect
try:
child=pexpect.spawn("./gmapPlayerCore.r &")
except:
print "Replaytool Execution Failed!!"
exit(1)
child.timeout=Timeout
child.logfile=stdout
status=child.expect(["[nN]o [sS]uch [fF]ile","",pexpect.TIMEOUT,pexpect.EOF])
if status==0:
print "gmapPlayerCore file is missing"
exit(1)
elif status==1:
print "Starting ReplayTool!!!"
else:
print "Timed out!!"
这里,虽然它在后台运行脚本退出的过程中spawn
也被甚至被杀害后
如何做到这一点?
'&'没有做任何事 - 这是在后台运行进程的bash语法,并且您没有通过bash运行它。我认为如果你在产生这个孩子的时候传递'preexec_fn = os.setsid',那么它应该从它的控制tty中分离出来,并且防止它被杀死。或者,如果您可以修改子流程中的代码,则可以使其忽略SIGHUP。 –