2018-04-27 00:00:22 +08:00
|
|
|
"""
|
|
|
|
创建进程调用其他程序
|
|
|
|
|
|
|
|
Version: 0.1
|
|
|
|
Author: 骆昊
|
|
|
|
Date: 2018-03-20
|
|
|
|
"""
|
|
|
|
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
|
|
|
def main():
|
2019-05-03 21:17:36 +08:00
|
|
|
# 通过sys.argv获取命令行参数
|
|
|
|
if len(sys.argv) > 1:
|
|
|
|
# 第一个命令行参数是程序本身所以从第二个开始取
|
|
|
|
for index in range(1, len(sys.argv)):
|
|
|
|
try:
|
|
|
|
# 通过subprocess模块的call函数启动子进程
|
|
|
|
status = subprocess.call(sys.argv[index])
|
|
|
|
except FileNotFoundError:
|
|
|
|
print('不能执行%s命令' % sys.argv[index])
|
|
|
|
else:
|
|
|
|
print('请使用命令行参数指定要执行的进程')
|
2018-04-27 00:00:22 +08:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2019-05-03 21:17:36 +08:00
|
|
|
main()
|