tags:

views:

123

answers:

3

for ex: i want to store output of system("dir");

Thanks & Regards, calvin

+2  A: 

You can either use redirection to a file (system( "dir > file" )), read that file and delete it or go the unnamed pipes way as in Unix - call CreatePipe() to create a pipe and attach it as the input/output stream in PROCESS_INFORMATION structure and pass that structure into CreateProcess().

sharptooth
yah i can tryout this simple thing, redirecting to a file.
calvin
+3  A: 

Yes, look at capturing stdout from CreateProcess:

Note that dir is a built in command under DOS. So you'll have to do something like the following system command:

  • cmd.exe /c dir c:\path\to\directory

rather than just calling dir. Type cmd /? for more information on the /c parameter.

ars
A: 

POSIX has a popen() function and I think that Windows has something similar called _popen().

AProgrammer
Which won't work with a Windows GUI app, only with a console.
anon