import os,subprocess
command=r'pyinstaller C:\Users\user\Desktop\Питон\hello_world.py'
output=os.popen(command)
print(output.read())
我想获取命令行的输出,但该方法只返回换行符('\n'):
>>>
如果您在命令行手动键入此命令,它将输出:
94 INFO: PyInstaller: 3.6
94 INFO: Python: 3.8.1
94 INFO: Platform: Windows-10-10.0.14393-SP0
98 INFO: wrote C:\Users\user\hello_world.spec
99 INFO: UPX is not available.
102 INFO: Extending PYTHONPATH with paths
['C:\\Users\\user\\Desktop\\Питон', 'C:\\Users\\user']
102 INFO: checking Analysis
102 INFO: Building Analysis because Analysis-00.toc is non existent
...
13823 INFO: Building COLLECT COLLECT-00.toc completed successfully.
这是我需要的输出我尝试了子进程模块的选项,结果是一样的:
output=subprocess.Popen(command,stdout=subprocess.PIPE)
print(output.communicate()[0].decode('utf-8'))
>>>