当我从 python 运行 可执行文件并通过参数时,我什么也没得到

When I run executable from python and pass the arguements I get nothing

这是我要使用的程序的 link:http://www.cs.jhu.edu/~misha/Code/ShapeSPH/ShapeDescriptor/ 我想 运行 通过 python 使用以下命令

import subprocess
args = ['C:\Path\ShapeDescriptor.exe', "--in", "x.ply", "--out", "x.txt" ]
subprocess.call(args, shell=True) 

但是当我 运行 它时,我得到类似的东西:

#QNAN0 1.#QNAN0 1.#QNAN0 -1.#IND00

我可以从命令提示符 运行 ShapeDescriptor.exe 作为:

ShapeDescriptor.exe --in x.ply -out x.txt

并获取所需的 x.txt 文件,例如:

0.003294 0.003386 0.003426 0.001029

我该如何解决这个问题?

如果拆分不起作用,您可能还想使用 cwd 参数提供工作目录。可能 x.txt 是在意外位置创建的。

尝试使用subprocess.call(args, *, stdin=None, stdout=None, stderr=None, shell=False)使用选项或 subprocess.check_call(args, *, stdin=None, stdout=None, stderr=None, shell=False)。

不同之处在于,如果处理 returns 一个错误代码,check_call 将得到一个 CalledProcessError。

另一种策略是使用chdir函数来改变当前执行exe文件的目录,如下:

导入os

os.chdir('c:\documents and settings\programs\')