in the following for loop, i print the version number of program installed
for program in sub3_required_programs:
try:
version = subprocess.call([program, '-i'])
print version + '\n'
except:
exit
But i actually want only the first line which has the version number. How can i restrict the print to only the first line
What’s the current print output? Unless you’re running a version of Python that behaves differently, it looks like the return status of the call is the only thing being assigned to version.
– docstring for
subprocess.callI bet the subprocess.call is the culprit, printing it’s output to STDOUT. Even if you didn’t have that print statement, you would still see all the output of the subprocess call due to the way the method works.
To grab the actual output, you might want to do something more like
The
communicatecall returns the tuple(stdoutdata, stderrdata). You can read more about it in the docs. Everything else should be self-explanatory.