Python subprocess.Popen - 添加GCC标志会导致"无输入文件"错误

2 python gcc subprocess popen

我正在构建一个Python脚本来自动化我的构建过程,它使用subprocess.Popen调用GCC.我最初的尝试工作正常.

>>> import subprocess
>>> p = Popen(['gcc', 'hello.c'], stdout=subprocess.PIPE, stderr=stderr=subprocess.STDOUT)
>>> p.wait()
0
>>> p.communicate()
('', None)
Run Code Online (Sandbox Code Playgroud)

但是,一旦我将其他选项传递给GCC,我会收到错误"无输入文件",如下所示:

>>> import subprocess
>>> p = Popen(['gcc', '-o hello hello.c'], stdout=subprocess.PIPE, stderr=stderr=subprocess.STDOUT)
>>> p.wait()
1
>>> p.communicate()
('gcc: no input files\r\n', None)
Run Code Online (Sandbox Code Playgroud)

可能导致此问题的任何想法?

edu*_*ffy 6

不应该这样

p = Popen(['gcc', '-o', 'hello', 'hello.c'], stdout=subprocess.PIPE, stderr=stderr=subprocess.STDOUT)
Run Code Online (Sandbox Code Playgroud)