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

  • Home
  • SEARCH
  • 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 9162743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:17:04+00:00 2026-06-17T14:17:04+00:00

I am trying to run an external program (in this case just python -V)

  • 0

I am trying to run an external program (in this case just python -V) and capture the standard error in the memory.

It works if I redirect to disk:

import sys, os
import subprocess
import tempfile
err = tempfile.mkstemp()
print err[1]
p = subprocess.call([sys.executable, '-V'], stderr=err[0] )

but that’s not fun. Then I’d need to read that file into memory.

I thought I can create something in-memory that would act like a file using StringIO but this attempt failed:

import sys, os
import subprocess
import tempfile
import StringIO

err = StringIO.StringIO()
p = subprocess.call([sys.executable, '-V'], stderr=err )

I got:

AttributeError: StringIO instance has no attribute 'fileno'

ps. Once this works I’ll want to capture stdout as well, but I guess that’s the same.
ps2. I tried the above on Windows and Python 2.7.3

  • 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-06-17T14:17:06+00:00Added an answer on June 17, 2026 at 2:17 pm

    You need to set stderr = subprocess.PIPE

    e.g.:

    p = subprocess.Popen(...,stderr = subprocess.PIPE)
    stdout,stderr = p.communicate()
    #p.stderr.read() could work too.
    

    note, for this to work, you need access to the Popen object, so you can’t really use subprocess.call here (you really need subprocess.Popen).

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

Sidebar

Related Questions

I'm trying to run an external program in SBCL and capture its output. The
Getting the following error when trying to run SPSS from an external Python IDE.
I'm trying to run an external, separate program from Python. It wouldn't be a
I'm new to Python. I'm trying to run this script (gencards.py) in Windows, but
I'm trying to launch an external program from my java swing app using this:
I am trying to run a external exe from a powershell script. This exe
I have run my program and everything works great. I am now trying to
I am trying to invoke external program (in my case IECapt.exe) in php function
I'm trying to run an external executable, but apparently it needs elevation. The code
I am trying run a program from a qmake .pro file which modifies the

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.