Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Accessing STDOUT of a child process


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Eliad Moshe   Members   -  Reputation: 813

Like
1Likes
Like

Posted 16 February 2014 - 06:39 PM

Hi guys,

I am trying to access the STDOUT of a child console application,
At first I tried to use Anonymous Pipes with Info from:

http://msdn.microsoft.com/en-us/library/ms682499%28VS.85%29.aspx
http://www.codeproject.com/Articles/5531/Redirecting-an-arbitrary-Console-s-Input-Output

then, I found this page at Microsoft Support : http://support.microsoft.com/kb/190351 that states:

"Note Child processes that use such C run-time functions as printf() and fprintf() can behave poorly when redirected. The C run-time functions maintain separate IO buffers. When redirected, these buffers might not be flushed immediately after each IO call. As a result, the output to the redirection pipe of a printf() call or the input from a getch() call is not flushed immediately and delays, sometimes-infinite delays occur. This problem is avoided if the child process flushes the IO buffers after each call to a C run-time IO function. Only the child process can flush its C run-time IO buffers. A process can flush its C run-time IO buffers by calling the fflush() function."

Any Idea what can I do in order to  solve this besides modifying the source?
 


Edited by Eliad Moshe, 16 February 2014 - 11:29 PM.


Sponsor:

#2 frob   Moderators   -  Reputation: 24205

Like
3Likes
Like

Posted 16 February 2014 - 07:33 PM

Hi guys,
I am trying to access the STDOUT of a console application,
At first I tried to use Anonymous Pipes with Info from:
...
Any Idea what can I do in order to  solve this besides modifying the source?

It is sometimes sad how Windows has sacrificed simplicity for security.

In the Unix world, the command is popen(). Give it a program to run, and the stdin and stdio come back to you as piped streams for reading and writing.


The first link you gave is the Windows way of doing it. Just pass a NULL security token to create the pipes, then create the process with a default security token,using the pipes you made.

Check out my book, Game Development with Unity, aimed at beginners who want to build fun games fast.

Also check out my personal website at bryanwagstaff.com, where I write about assorted stuff.


#3 Eliad Moshe   Members   -  Reputation: 813

Like
0Likes
Like

Posted 16 February 2014 - 07:40 PM

Thanks frob for your help,

Should it works well with function calls like printf() at the called child process?
I used this source as a reference and the Read function from the calling process is blocking 'infinitely'..

 



#4 frob   Moderators   -  Reputation: 24205

Like
0Likes
Like

Posted 16 February 2014 - 08:50 PM

Probably.

In the Unix world people are very careful about getting data from stdin and stdout, building tools that are lightweight and are designed to be invoked by other programs.

In the Windows world, everything is designed around the screen. Many programs unintentionally (or intentionally) will not work when invoked by other programs.

If the program is getting input from the stdin stream and writing to stdout, then yes, everything should work. You need to feed it all the data that would normally be typed by the user and you need to read the values that would show up on the screen.

If the program tries to get fancy with non-stream console I/O or creating its own text console or doing other stuff that is increasingly common in the Windows world, then all bets are off.

Check out my book, Game Development with Unity, aimed at beginners who want to build fun games fast.

Also check out my personal website at bryanwagstaff.com, where I write about assorted stuff.


#5 Eliad Moshe   Members   -  Reputation: 813

Like
0Likes
Like

Posted 16 February 2014 - 10:53 PM

If the program tries to get fancy with non-stream console I/O or creating its own text console or doing other stuff that is increasingly common in the Windows world, then all bets are off.

Yep //






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS