Re: Possible to execute another program and capture its stdout in 'C'?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance





ohaya wrote:


Nathan Mates wrote:

In article <uQmnQPj1JHA.1196@xxxxxxxxxxxxxxxxxxxx>,
ohaya <ohaya@xxxxxxx> wrote:

I am working on a command line application, where it builds a command line for executing another program, and I need to be able to "capture" the stdout from that other program for processing in my app.



http://msdn.microsoft.com/en-us/library/ms682499(VS.85).aspx
should do the trick.

Nathan Mates


Nathan,

Thanks quick response and for the link. I'll take a look at it and will post back.

Later,
Jim



Hi,

In my case, I didn't want to pipe anything into the command my app is running, so I used the example code in that link, and commented out:

/*
if (argc == 1)
ErrorExit(TEXT("Please specify an input file.\n"));

g_hInputFile = CreateFile(
argv[1],
GENERIC_READ,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_READONLY,
NULL);

if ( g_hInputFile == INVALID_HANDLE_VALUE )
ErrorExit(TEXT("CreateFile"));

// Write to the pipe that is the standard input for a child process.
// Data is written to the pipe's buffers, so it is not necessary to wait
// until the child process is running before writing data.

WriteToPipe();
printf( "\n->Contents of %s written to child STDIN pipe.\n", argv[1]);
*/

I also set the szCmdline:

TCHAR szCmdline[]=TEXT("dumpbin /imports C:\\WINDOWS\\system32\\drivers\\xxx.sys");

[My app is running dumpbin.exe on some of the files in system32\drivers.]

When I run the resulting .exe, I can see the output of dumpbin in the console window, and then:

->Start of parent execution.

->Contents of child process STDOUT:


->End of parent execution.

In other words, it looks like it's not getting anything from ReadFromPipe()?

Any idea what I might be doing wrong?

Thanks again,
Jim

.



Relevant Pages

  • Re: Possible to execute another program and capture its stdout in C?
    ... ohaya wrote: ... Nathan Mates wrote: ... command line for executing another program, and I need to be able to "capture" the stdout from that other program for processing in my app. ... // Write to the pipe that is the standard input for a child process. ...
    (microsoft.public.vc.language)
  • Re: Possible to execute another program and capture its stdout in C?
    ... Nathan Mates wrote: ... line for executing another program, and I need to be able to "capture" the stdout from that other program for processing in my app. ...
    (microsoft.public.vc.language)
  • Re: forking in c
    ... each child process should have a child process of their own. ... > meanwhile the parent process will have a childpid greater then 0 and it will ... Outside of failures in fork(), the parent /is/ creating new child processes ... continues executing from the first fork ...
    (comp.unix.programmer)
  • Re: does IO.read block?
    ... Assume an application as a child process that frequently writes to stdout and stderr. ... The parent process at the other end of those two pipes only reads the stdout pipe. ...
    (comp.lang.ruby)
  • Re: [ANN] open4-0.8.0
    ... $ sudo gem install open4 ... open child process with handles on pid, stdin, stdout, and stderr: ...
    (comp.lang.ruby)