Tech Support > Computers & Technology > Programming > Capturing stderr from Spawn process in C
Capturing stderr from Spawn process in C
Posted by Oscar van den Bosch on December 3rd, 2003


I want to create a GUI in Win32 that launches a command line tool.
Now I can launch the commandline tool use the spawn() function from
process.h, but I cannot figure out how to capture the stdout or sterr
afterwards.

launching the app as follows :

spawnl(P_WAIT, "c:\\app.exe 2> err.log", "app.exe 2> err.log", NULL);

Doesn't seem to work.
Can anyone help me with this?

Oscar

Posted by Willem on December 3rd, 2003


Oscar wrote:
) I want to create a GUI in Win32 that launches a command line tool.
) Now I can launch the commandline tool use the spawn() function from
) process.h, but I cannot figure out how to capture the stdout or sterr
) afterwards.
)
) launching the app as follows :
)
) spawnl(P_WAIT, "c:\\app.exe 2> err.log", "app.exe 2> err.log", NULL);
)
) Doesn't seem to work.
) Can anyone help me with this?

You may want to try using 'system', otherwise you'll have to do ugly stuff
with dup2 and fork.


SaSW, Willem (at stack dot nl)
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT

Posted by Oscar van den Bosch on December 3rd, 2003


Thanks willem, that worked just fine.
Is there any way in which you can prevent the dosbox from popping up
after calling system().

Oscar

On Wed, 3 Dec 2003 16:12:40 +0000 (UTC), Willem <willem@stack.nl>
wrote:

Posted by Corey Murtagh on December 4th, 2003


Oscar van den Bosch wrote:

Not using the system() command, no. You might want to check the
available Win32 API functions if you need to fine-tune things. I'd
suggest looking up CreateProcessEx().

--
Corey Murtagh
The Electric Monk
"Quidquid latine dictum sit, altum viditur!"


Posted by Programmer Dude on December 4th, 2003


Oscar van den Bosch wrote:

Check out CreateProcess();

--
|_ CJSonnack <Chris@Sonnack.com> _____________| How's my programming? |
|_ http://www.Sonnack.com/ ___________________| Call: 1-800-DEV-NULL |
|_____________________________________________|___ ____________________|

Posted by jdionne@sdcnov1.sdcweb.net on December 4th, 2003


A technique I perfer is popen(). Works on M$ too.

Programmer Dude wrote:


Similar Posts