我可以像这样同时运行三个脚本:
python script1.py ; python script2.py ; python script3.py
但是当我尝试在后台运行它们时,如下所示:
python script1.py & ; python script2.py & ; python script3.py &
我明白了:
syntax error near unexpected token `;'
我也尝试在最后只使用一个“&”符号,但这只会导致后台运行一个进程。
我想用一个命令启动它们,因为脚本会不断地打印到屏幕上,导致输入新命令很困难。我该怎么做?
(如果您的想法倾向于这个方向,脚本没有 main() 函数。)
答案1
正确的语法是
python script1.py & python script2.py & python script3.py &
我的参考资料man bash
在以下Lists
部分:
Lists A list is a sequence of one or more pipelines separated by one of the operators ;, &, &&, or ||, and optionally terminated by one of ;, &, or <newline>. [...] If a command is terminated by the control operator &, the shell executes the command in the background in a subshell. The shell does not wait for the command to finish, and the return status is 0.