1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| PROCESS_INFORMATION piProcessInfo;
SECURITY_ATTRIBUTES sa_attr;
HANDLE hChildStdinRd, hChildStdinWr, hChildStdoutRd, hChildStdoutWr, hChildStderrRd, hChildStderrWr;
// Set the bInheritHandle flag so pipe handles are inherited.
sa_attr.nLength = sizeof( SECURITY_ATTRIBUTES );
sa_attr.bInheritHandle = TRUE;
sa_attr.lpSecurityDescriptor = NULL;
// Create a pipe for the child process's STDERR.
CreatePipe( &hChildStderrRd, &hChildStderrWr, &sa_attr, 0 );
// Ensure that the read handle to the child process's pipe for STDOUT is not inherited.
SetHandleInformation( hChildStderrRd, HANDLE_FLAG_INHERIT, 0 );
// Create a pipe for the child process's STDOUT.
CreatePipe( &hChildStdoutRd, &hChildStdoutWr, &sa_attr, 0 );
// Ensure that the read handle to the child process's pipe for STDOUT is not inherited.
SetHandleInformation( hChildStdoutRd, HANDLE_FLAG_INHERIT, 0 );
// Create a pipe for the child process's STDIN.
CreatePipe( &hChildStdinRd, &hChildStdinWr, &sa_attr, 0 );
// Ensure that the write handle to the child process's pipe for STDIN is not inherited.
SetHandleInformation( hChildStdinWr, HANDLE_FLAG_INHERIT, 0 );
// Startup information.
STARTUPINFO siStartupInfo;
FWK_System::bzero( (FWK_Byte *) &siStartupInfo, sizeof( siStartupInfo ) );
siStartupInfo.cb = sizeof( STARTUPINFO );
siStartupInfo.hStdError = hChildStderrWr;
siStartupInfo.hStdOutput = hChildStdoutWr;
siStartupInfo.hStdInput = hChildStdinRd;
siStartupInfo.dwFlags |= STARTF_USESTDHANDLES;
// Launch the process.
BOOL status = CreateProcess( path.to_char(),
cmd_line.to_char(),0,0,FALSE,
CREATE_DEFAULT_ERROR_MODE,0,0,
&siStartupInfo, &piProcessInfo ); |