CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
jackfrued

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: jackfrued/Python-100-Days
Path: blob/master/Day01-15/code/Day13/multiprocess3.py
Views: 729
1
"""
2
创建进程调用其他程序
3
4
Version: 0.1
5
Author: 骆昊
6
Date: 2018-03-20
7
"""
8
9
import subprocess
10
import sys
11
12
def main():
13
# 通过sys.argv获取命令行参数
14
if len(sys.argv) > 1:
15
# 第一个命令行参数是程序本身所以从第二个开始取
16
for index in range(1, len(sys.argv)):
17
try:
18
# 通过subprocess模块的call函数启动子进程
19
status = subprocess.call(sys.argv[index])
20
except FileNotFoundError:
21
print('不能执行%s命令' % sys.argv[index])
22
else:
23
print('请使用命令行参数指定要执行的进程')
24
25
26
if __name__ == '__main__':
27
main()
28
29