带参数的 Python 子进程

用户1670773

test.py使用 python 子进程运行 python 脚本我想发送两个字符串'John', 'Henry'作为参数并从 test.py 中读取参数值。我想要这样的东西

subprocess.call(['python3', 'test.py']) #add two names 'John', 'Henry' as argument

测试文件

print(name1) #print John
print(name2) #print Henry

我怎样才能做到这一点?

安德鲁·哈尔

试试这个:

subprocess.call(['python3', 'test.py', 'John', 'Henry'])

并将 test.py 更改为如下所示:

import sys

print(sys.argv[1])
print(sys.argv[2])

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章