python - Pyinstaller 在 Windows 下的 onefile 可执行文件上出现 subprocess.check_output 问题

标签 python windows subprocess pyinstaller

需要运行 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/

相关文章:

Python:针对函数的一个变量进行绘图

windows - 使用 IE9 嵌入 WebBrowser 控件时覆盖 IE 设置

c# - Windows 注册表中的 Mime 类型

windows - 使用Golang在Windows的端口上启动服务器可执行文件

php - python 纹 : download file accessible through PHP script

python - 将组合的 IntFlag 分解为其单独的标志

python - 使用 DPKT 了解 http 请求是 GET 还是 POST 的最佳方法?

python - subprocess.Popen - 没有这样的文件或目录

python - 带双引号的子流程

python - Popen 混淆 - 重定向输出,方法不起作用