【发布时间】:2020-10-08 10:31:54
【问题描述】:
我有 4 个 python 和 shell 脚本,我想从一个 python 脚本一个接一个地运行它们。
那么让我们说:
import script1
import script2
import script3
python script1.py &
#do something here to check if script1 has been completed and move to script 2
python script2.py &
#do something here to check if script2 has been completed and move to script 3
python script3.py &
#do something here to check if script3 has been completed and move to script 4 which is a shell script.
有人可以帮忙吗?提前致谢!
【问题讨论】:
-
他们定义了
main函数吗?他们有if __name == 'main':子句吗? -
不,那些脚本没有这个子句。
-
所以
import应该让它们运行(它确实只是执行脚本......) -
docs.python.org/3/library/… 是这样的吗?
-
尝试养成将 shebang 作为脚本第一行的习惯,以便读者和内核知道您正在为哪个解释器编写代码,这样您就不必继续输入
python script.py一直都是。
标签: python shell subprocess