我有一个Python脚本,它接收输入并将其格式化为调用服务器上另一个脚本的命令,然后使用子进程执行:
import sys, subprocess
thingy = sys.argv[1]
command = 'usr/local/bin/otherscript.pl {0} &'.format(thingy)
command_list = command.split()
subprocess.call(command_list)
我在结尾添加了&
,因为otherscript.pl
需要一些时间来执行,而我更喜欢后台运行。不过,这个脚本似乎仍然在执行,没有将控制权还给我的shell,我必须等待执行完成才能返回提示符。有没有另一种使用subprocess
完全在后台运行脚本的方法?
call
更加灵活 - 需要更多的开销,但它可以提供你想要的控制。 - Mostly Harmless