Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python subprocess.Popen - adding GCC flags results in "no input files" error

I'm building a Python script to automate my build process, which invokes GCC using subprocess.Popen. My initial attempt works fine.

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

However, once I pass additional options to GCC I get the error "no input files", as demonstrated below:

>>> 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)

Any ideas what may be causing this issue?


1 Answers

Shouldn't that be

p = Popen(['gcc', '-o', 'hello', 'hello.c'], stdout=subprocess.PIPE, stderr=stderr=subprocess.STDOUT)
like image 186
eduffy Avatar answered Jan 31 '26 02:01

eduffy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!