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 8588411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:47:47+00:00 2026-06-11T22:47:47+00:00

I have a program that I would like to launch via subprocess. It can

  • 0

I have a program that I would like to launch via subprocess. It can output to fd other than stdout and stderr. Is there a way to capture data from an arbitrary fd? I’d like to do something like the following, if my process is sending output to fd 9:

import subprocess, StringIO
redirector = StringIO.StringIO()
errno = subprocess.call(cmd, fd9=redirector)
#process the error code and data in redirector

I do not want to redirect the called process’s output to fd 9 through stderr or stdout.

  • 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-11T22:47:48+00:00Added an answer on June 11, 2026 at 10:47 pm

    If the program opens file descriptor 9 (or whatever) after it starts running, then there is no way to do what you want.

    If the program does not open file descriptor 9 itself, but gets it from the parent process, then you can do what you want with the preexec_fn argument to subprocess.Popen, but it is not as simple as setting something to a StringIO instance. You have to create a pipe by hand, and you have to arrange to read from it in a timely fashion, or you will cause a deadlock. Expect to write two or three hundred lines of code to get this 100% right. I’m not going to put any sample code here because I don’t want to make it look easier than it is.

    In addition to subprocess.Popen, you will need os.pipe, os.dup2, and os.read, and you will need to understand the underlying system primitives:
    pipe(2), dup2(2), read(2), fork(2), and execve(2).

    Now might be a good time to invest in a copy of Advanced Programming in the Unix Environment.

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

Sidebar

Related Questions

I have a program that generates/'rolls' two dice. I would like to output these
I would like to have a small application loader program that receives other binary
I have a Datatable in my C# program that I would like to INSERT
I have a program that reads data from a file line-by-line. I would like
I have a java program that is running in the background(Windows). I would like
I have completed my program and would like to send that program in its
I have a 3rd-party installer program that I would like for my users to
I have a program that I'm working on that register global hotkeys I would
I have a C++ program that crashed due to a bug. It would not
How would I get the main program to recognize that I have an outside

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.