&是外壳功能。如果要与一起使用
subprocess,则必须指定
shell=True类似:
subprocess.call(command, shell=True)
这将允许您在后台运行命令。
笔记:
由于
shell=True
,以上用途command
,并非如此command_list
。使用
shell=True
启用了外壳的所有功能。除非command
包含thingy
来自您信任的来源,否则请不要这样做。
更安全的选择
此替代方法仍然可以让您在后台运行命令,但是安全,因为它使用默认值
shell=False:
p = subprocess.Popen(command_list)
执行此语句后,该命令将在后台运行。如果要确保已完成,请运行
p.wait()。



