CreateProcess() anomaly
-
:mad::confused: X| Hi everyone I am running the following piece of code on Windows 2000 and XP (except the code below has been simplified with error checking removed). This code spawns a child process, which writes its output to a logfile called child.log. The problem I am having is: if the child process is a command or batch file (example below), then child.log captures output of commands such as "dir", however, for any processes that are launched from the batch script, such as perl.exe, all the output is lost. I don't know where the output is going or why. I suspect I have done something wrong with handle inheritance somewhere.. any ideas?? I don't get the same problem if the child process is some other shell interpreter, such as bash.exe. ......................... SECURITY_ATTRIBUTES secAttr; secAttr.nLength = sizeof(SECURITY_ATTRIBUTES); secAttr.bInheritHandle = TRUE; secAttr.lpSecurityDescriptor = NULL; STARTUPINFO startupInfo; ::ZeroMemory((void*) &startupInfo, sizeof(STARTUPINFO)); startupInfo.cb = sizeof(STARTUPINFO); startupInfo.dwFlags = STARTF_USESTDHANDLES; PROCESS_INFORMATION processInfo; startupInfo.hStdOutput = CreateFile( "child.log", GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, &secAttr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH | FILE_FLAG_SEQUENTIAL_SCAN, NULL); startupInfo.hStdError = startupInfo.hStdOutput; CreateProcess( NULL, "test.bat", NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &startupInfo, &processInfo); // Close handle because parent process has no further need for it: CloseHandle(startupInfo.hStdOutput); .................. Example of test.bat: ---------------------------- rem test.bat rem dir command gives output in child.log, but "perl -v" does not !! dir perl -v exit 0 cheers, Neil