需要运行 subprocess.check_output
来捕获我的应用程序中 7zip 的输出。我使用的简单代码是
output = subprocess.check_output(["path/to/7zip", "l", "path/to/archieve"], shell=True)
print output
正如预期的那样,当我从 IDE 运行它时它运行良好。使用 pyinstaller 编译成 onefile 可执行文件后,同样会变得疯狂并且无法工作。即使将脚本转换为可执行文件后,另一个子进程命令 subprocess.call
也能正常工作。如何在可执行文件中使用 subprocess.check_output
?
我使用以下内容:-
Windows 7
Python 2.7.5
PyQt4
Pyinstaller 2.1
感谢任何帮助。
最佳答案
好的。自己解决了。使用 os.popen 命令完成相同的任务。为了完整起见,发布以下解决方案代码:-
out = os.popen("path/to/7zip l path/to/archieve").read()
print out
关于python - Pyinstaller 在 Windows 下的 onefile 可执行文件上出现 subprocess.check_output 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21483414/