Python subprocess.run是';在使用pyinstaller和--noconsole--onefile时无法工作

Python subprocess.run是';在使用pyinstaller和--noconsole--onefile时无法工作,python,subprocess,Python,Subprocess,我正在使用Pyinstaller 3.6、Python3.8.3,在编译此代码时(使用标志--onefile): 一切正常。下面是output.txt文件: Volume in drive C has no label. Volume Serial Number is E612-C89D Directory of C:\Users\trolo\OneDrive\Desktop\progs\tests\dist 14.07.2020 12:11 <DIR>

我正在使用Pyinstaller 3.6、Python3.8.3,在编译此代码时(使用标志--onefile):

一切正常。下面是output.txt文件:

 Volume in drive C has no label.

 Volume Serial Number is E612-C89D

 Directory of C:\Users\trolo\OneDrive\Desktop\progs\tests\dist

14.07.2020  12:11    <DIR>          .
14.07.2020  12:11    <DIR>          ..
14.07.2020  11:58         9я777я078 test3.exe

               1 File(s)      9я777я078 bytes
               2 Dir(s)  12я544я409я600 bytes free
[WinError 6] The handle is invalid

出了什么问题,如何在不显示控制台窗口的情况下使其工作?

Python3:您只需传递stdin=subprocess.DEVNULL即可

subprocess.Popen( args=[self.exec_path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.DEVNULL)
Python2.x:您需要将filehandler设置为null,然后将其传递给popen

devnull = open(os.devnull, 'wb')
subprocess.Popen( args=[self.exec_path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=devnull)

这帮了大忙。谢谢
devnull = open(os.devnull, 'wb')
subprocess.Popen( args=[self.exec_path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=devnull)