Python- 运行外部命令时的传递参数

2024-04-29 15:53:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在调用一个像这样的外部程序

call(["./myProgram", myArgs])

我如何传递参数列表?myProgram有3个参数,如下所示

^{pr2}$

单独指定参数如下所示

call(["./myProgram", param1 ,param2, param3])

,但如何使用参数列表/数组,例如

myArgs=[param1,param2,param3]

我得到了这个

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/subprocess.py", line 493, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
raise child_exception TypeError: execv() arg 2 must contain only strings

Tags: inpy列表参数libusrlinecall