我要建一个Python脚本来自动编译过程中,GCC使用subprocess.Popen其调用。我最初的尝试工作正常。

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

然而,一旦予传递额外的选项,以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)

任何想法可能会造成这个问题?

有帮助吗?

解决方案

不应该认为是

p = Popen(['gcc', '-o', 'hello', 'hello.c'], stdout=subprocess.PIPE, stderr=stderr=subprocess.STDOUT)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top