1

I've searched fairly thoroughly for an answer, but haven't found any solutions to this.

I need to execute a child process only momentarily to print its version information. If run from the command line, it's simply

.\bin\application.exe --version

and version information is printed to the terminal. I'd like to capture that information in a string. I've been trying out variants of

args = ("path\to\application.exe", "--version")
subprocess.Popen(args, stdout=subprocess.PIPE).communicate()[0]

with no success. I also need this not to print the output to the terminal, if possible. What can I do?

3
  • 4
    Is the application printing the version information to STDERR? Try adding stderr=subprocess.STDOUT to your Popen call and see what happens. Commented Feb 14, 2014 at 20:34
  • Glad to help! I added an answer for better visibility for people who come across this question later. Commented Feb 14, 2014 at 20:44
  • note: if you want to discard the output then you should use DEVNULL instead of PIPE otherwise you can run out of memory if the child process generates enough output. Commented Feb 18, 2014 at 9:47

1 Answer 1

3

Sometimes applications dump version information to STDERR instead of STDOUT.

You can capture both like this:

args = ("path\to\application.exe", "--version")
subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT).communicate()[0]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.