[英]subprocess seems not working in pyinstaller exe file
My program in tkinter
is working well when I am running it using PyCharm
, when I am creating .exe
file using pyinstaller,我在节目tkinter
运作良好时,我使用的是运行它PyCharm
,当我创建.exe
使用pyinstaller文件,
pyinstaller -i"icon.ico" -w -F script.py
I have no errors.我没有错误。 I am pasting script.exe
in same folder as my script.py
, and after running it I think in step where subprocess
is, it is not answering, because I have print
before subprocess line and its working.我粘贴script.exe
在同一文件夹中我script.py
,并运行它后,我觉得在步骤中subprocess
,它是不回答,因为我有print
之前子行和其工作。
Anyone know why?有谁知道为什么?
This is the line with subprocess:这是带有子进程的行:
import subprocess
from subprocess import Popen, PIPE
s = subprocess.Popen([EXE,files,'command'],shell=True, stdout=subprocess.PIPE)
EDIT:编辑:
same problem with:同样的问题:
s = subprocess.check_output([EXE,files,'command'],shell=True, stderr=subprocess.STDOUT)
You can compile your code in -w mode or --windowed, but then you have to assign stdin and stderr as well.您可以在-w 模式或--windowed 下编译代码,但是您还必须分配stdin 和stderr。
So change:所以改变:
s = subprocess.Popen([EXE,files,'command'],shell=True, stdout=subprocess.PIPE)
to:到:
s = subprocess.Popen([EXE,files,'command'],shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
通过不使用-w
命令从 .py 脚本生成 exe 文件解决了问题。
Use this function to get the command's output instead.使用此函数来获取命令的输出。 Works with -F and -w option:与 -F 和 -w 选项一起使用:
import subprocess
def popen(cmd: str) -> str:
"""For pyinstaller -w"""
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
process = subprocess.Popen(cmd,startupinfo=startupinfo, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
return decode_utf8_fixed(process.stdout.read())
I was getting the error [WinError 6] The handle is invalid
when running the line我收到错误[WinError 6] The handle is invalid
运行该行时[WinError 6] The handle is invalid
data = subprocess.check_output(['netsh', 'wlan', 'show', 'profiles']).decode('utf-8').split('\n')
This solved it for me: https://stackoverflow.com/a/43606682/12668094这为我解决了: https : //stackoverflow.com/a/43606682/12668094
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.