Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3958722
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:38:35+00:00 2026-05-20T02:38:35+00:00

I am Using Python 2.7.1 on a Windows Server 2008 R2 x64 box. I’m

  • 0

I am Using Python 2.7.1 on a Windows Server 2008 R2 x64 box.

I’m trying to get the output of a command line process which gives a nonzero exit status after outputting the information I need.

I was initially using subprocess.check_output, and catching the CalledProcessError which occurs with nonzero exit status, but while the returncode was stored in the error, no output revealed this.

Running this against cases which give output but have an exit status of 0 works properly and I can get the output using subprocess.check_output.

My assumption was that the output was being written to STDOUT but the exception pulls its ‘output’ from STDERR. I’ve tried to re implement the functionality of check_output, but I still get nothing on the output when I believe I should be seeing output to STDOUT and STDERR. My current code is below (where ‘command’ is the full text, including parameters, of command I am running:

process = subprocess.Popen(command, stdout=subprocess.PIPE, 
stderr=subprocess.STDOUT, universal_newlines=True)
output = process.communicate()
retcode = process.poll()
if retcode:
    raise subprocess.CalledProcessError(retcode, image_check, output=output)
    return output 

This gives me the following in the variable output: [('', None)]

Is my subprocess.Popen code correct?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T02:38:36+00:00Added an answer on May 20, 2026 at 2:38 am

    You code works fine. Turns out that the process that you are calling is probably outputing to CON. See the following example

    import subprocess
    
    def check_output(command):
        process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
        output = process.communicate()
        retcode = process.poll()
        if retcode:
                raise subprocess.CalledProcessError(retcode, command, output=output[0])
        return output 
    
    command = "echo this>CON"
    
    print "subprocess -> " + subprocess.check_output(command, shell=True)
    print "native -> " + str(check_output(command))
    
    try:
        subprocess.check_output("python output.py", shell=True)
    except subprocess.CalledProcessError, e:
        print "subproces CalledProcessError.output = " + e.output
    
    try:
        check_output("python output.py")
    except subprocess.CalledProcessError, e:
        print "native CalledProcessError.output = " + e.output
    

    Output

    subprocess -> 
    native -> ('', None)
    stderr subproces CalledProcessError.output = stdout
    native CalledProcessError.output = stderr stdout
    

    Sadly, I do not know how to resolve the issue. Notice that subprocess.check_output results contains only the output from stdout. Your check_output replacement would output both stderr and stdout.

    After inspecting subprocess.check_output, it does indeed generate a CalledProcessError with the output containing only stdout.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When using the hg serve command in windows, the server starts correctly, but when
When using urllib2 (and maybe urllib) on windows python seems to magically pick up
Using Python 2.6, I wrote a script in Windows XP. The script does the
I am using python for making a COM local server. In fact, the whole
Using Python I want to be able to draw text at different angles using
Using python 2.4 and the built-in ZipFile library, I cannot read very large zip
Using Python, how would I go about reading in (be from a string, file
Using Python 2.6, is there a way to check if all the items of
Using Python's Imaging Library I want to create a PNG file. I would like
When using Python's super() to do method chaining, you have to explicitly specify your

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.