一直在尝试使类似的东西工作一段时间,以下内容似乎并未将正确的arg发送到c程序arg_count,后者输出argc = 1
。当我确定自己想要的时候2
。./arg_count -arg
从外壳输出2 ...
我尝试了另一个arg(因此它将在shell中输出3),并且在通过子进程调用时仍输出1。
import subprocess
pipe = subprocess.Popen(["./args/Release/arg_count", "-arg"], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = pipe.communicate()
result = out.decode()
print "Result : ",result
print "Error : ",err
知道我在哪里摔倒吗?我正在运行linux btw。
从文档中:
shell参数(默认为False)指定是否将shell用作要执行的程序。如果shell为True,建议将args作为字符串而不是序列传递。
从而,
pipe = subprocess.Popen("./args/Release/arg_count -arg", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
应该给你你想要的。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句