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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:20:21+00:00 2026-05-10T19:20:21+00:00

I have a project that I thought was going to be relatively easy, but

  • 0

I have a project that I thought was going to be relatively easy, but is turning out to be more of a pain that I had hoped. First, most of the code I’m interacting with is legacy code that I don’t have control over, so I can’t do big paradigm changes.

Here’s a simplified explanation of what I need to do: Say I have a large number of simple programs that read from stdin and write to stdout. (These I can’t touch). Basically, input to stdin is a command like ‘Set temperature to 100’ or something like that. And the output is an event ‘Temperature has been set to 100’ or ‘Temperature has fallen below setpoint’.

What I’d like to do is write an application that can start a bunch of these simple programs, watch for events and then send commands to them as necessary. My initial plan was to something like popen, but I need a bidrectional popen to get both read and write pipes. I hacked something together that I call popen2 where I pass it the command to run and two FILE* that get filled with the read and write stream. Then all I need to do is write a simple loop that reads from each of the stdouts from each of the processes, does the logic that it needs and then writes commands back to the proper process.

Here’s some pseudocode

FILE *p1read, *p1write; FILE *p2read, *p2write; FILE *p3read, *p3write;  //start each command, attach to stdin and stdout popen2('process1',&p1read,&p1write); popen2('process2',&p2read,&p2write); popen2('process3',&p3read,&p3write);  while (1) {    //read status from each process    char status1[1024];    char status2[1024];    char status3[1024];    fread(status1,1024,p1read);    fread(status2,1024,p2read);    fread(status3,1024,p3read);     char command1[1024];    char command2[1024];    char command3[1024];    //do some logic here     //write command back to each process    fwrite(command1,p1write);    fwrite(command2,p2write);    fwrite(command3,p3write); } 

The real program is more complicated where it peeks in the stream to see if anything is waiting, if not, it will skip that process, likewise if it doesn’t need to send a command to a certain process it doesn’t. But this code gives the basic idea.

Now this works great on my UNIX box and even pretty good on a Windows XP box with cygwin. However, now I need to get it to work on Win32 natively.

The hard part is that my popen2 uses fork() and execl() to start the process and assign the streams to stdin and stdout of the child processes. Is there a clean way I can do this in windows? Basically, I’d like to create a popen2 that works in windows the same way as my unix version. This way the only windows specific code would be in that function and I could get away with everything else working the same way.

Any Ideas?

Thanks!

  • 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. 2026-05-10T19:20:21+00:00Added an answer on May 10, 2026 at 7:20 pm

    On Windows, you invoke CreatePipe first (similar to pipe(2)), then CreateProcess. The trick here is that CreateProcess has a parameter where you can pass stdin, stdout, stderr of the newly-created process.

    Notice that when you use stdio, you need to do fdopen to create the file object afterwards, which expects file numbers. In the Microsoft CRT, file numbers are different from OS file handles. So to return the other end of CreatePipe to the caller, you first need _open_osfhandle to get a CRT file number, and then fdopen on that.

    If you want to see working code, check out _PyPopen in

    http://svn.python.org/view/python/trunk/Modules/posixmodule.c?view=markup

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

Sidebar

Ask A Question

Stats

  • Questions 82k
  • Answers 82k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You could also plug into Windows Instrumentation with you own… May 11, 2026 at 4:43 pm
  • Editorial Team
    Editorial Team added an answer Are you using require_once() to include common.php everywhere? If you… May 11, 2026 at 4:43 pm
  • Editorial Team
    Editorial Team added an answer I would not check the username availability in the model… May 11, 2026 at 4:43 pm

Related Questions

I’m working on an in-house app that tracks a bunch of tasks. I wanted
I'm working on a small UML editor project, in Java, that I started a
I was using a CASE called MAGIC for a system I'm developing, I've never
I actually have two questions regarding the same problem but I think it is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.