[英]Calling python script with arguments from a wrapper script
What I am trying to do is create a wrapper script, let's say program1.py
, that calls program2.py
and program3.py
from main()
. 我正在尝试做的是创建一个包装脚本,例如
program1.py
,该脚本从main()
调用program2.py
和program3.py
。 program1.py
, program2.py
, and program3.py
all need to have their own arguments. program1.py
, program2.py
和program3.py
都需要具有自己的参数。 What is the best way to go about creating this wrapper script? 创建此包装器脚本的最佳方法是什么? Should I prompt the user before running the
program2.py
script from program1.py
's main method? 我应该在从
program1.py
的main方法运行program2.py
脚本之前提示用户吗?
when passing arguments to Subprocess you need to pass it a list containing each word in the command you want to execute eg 当将参数传递给Subprocess时,您需要传递一个包含要执行的命令中每个单词的列表,例如
subprocess.Popen(['python', 'program2.py', argv[1], argv[2]])
would execute program 2 with the arguments argv[1] and argv[2] of the wrapper process. 将使用包装程序的参数argv [1]和argv [2]执行程序2。
If argv[1] = 'hello'
and argv[2] = 'world'
如果
argv[1] = 'hello'
和argv[2] = 'world'
python program2.py hello world
would be executed. 将被执行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.