Click here to Skip to main content
16,018,460 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: runing a console app from a batch file with indefinite params Pin
toxcct5-Oct-06 23:51
toxcct5-Oct-06 23:51 
QuestionQuestion about table Pin
zizzzz5-Oct-06 23:23
zizzzz5-Oct-06 23:23 
QuestionRe: Question about table Pin
prasad_som5-Oct-06 23:38
prasad_som5-Oct-06 23:38 
AnswerRe: Question about table Pin
toxcct5-Oct-06 23:56
toxcct5-Oct-06 23:56 
AnswerRe: Question about table Pin
Hamid Taebi6-Oct-06 8:35
professionalHamid Taebi6-Oct-06 8:35 
QuestionDirectShow: Knowing video buffer alignment of output frame inside DMO Pin
Johniteq5-Oct-06 23:01
Johniteq5-Oct-06 23:01 
AnswerRe: DirectShow: Knowing video buffer alignment of output frame inside DMO Pin
Johniteq5-Oct-06 23:33
Johniteq5-Oct-06 23:33 
NewsProblem with Batch Scripts and CreateProcess() Pin
neilsolent5-Oct-06 22:40
neilsolent5-Oct-06 22:40 
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, 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,
commandString,
NULL,
NULL,
TRUE,
DETACHED_PROCESS,
NULL,
NULL,
&startupInfo,
&processInfo);

// Close handle because parent process has no further need for it:
CloseHandle(startupInfo.hStdOutput);





<div class="ForumSig">
cheers,
Neil</div>
GeneralRe: Problem with Batch Scripts and CreateProcess() Pin
S Douglas6-Oct-06 13:46
professionalS Douglas6-Oct-06 13:46 
GeneralRe: Problem with Batch Scripts and CreateProcess() Pin
neilsolent7-Oct-06 8:41
neilsolent7-Oct-06 8:41 
GeneralRe: Problem with Batch Scripts and CreateProcess() Pin
S Douglas7-Oct-06 9:12
professionalS Douglas7-Oct-06 9:12 
GeneralRe: Problem with Batch Scripts and CreateProcess() Pin
neilsolent7-Oct-06 9:32
neilsolent7-Oct-06 9:32 
QuestionData types in Visual C++ Pin
Eikthrynir5-Oct-06 22:33
Eikthrynir5-Oct-06 22:33 
AnswerRe: Data types in Visual C++ Pin
Link20065-Oct-06 23:24
Link20065-Oct-06 23:24 
AnswerRe: Data types in Visual C++ Pin
toxcct6-Oct-06 0:00
toxcct6-Oct-06 0:00 
AnswerRe: Data types in Visual C++ Pin
Gary R. Wheeler6-Oct-06 3:04
Gary R. Wheeler6-Oct-06 3:04 
GeneralRe: Data types in Visual C++ Pin
Eikthrynir6-Oct-06 6:42
Eikthrynir6-Oct-06 6:42 
AnswerRe: Data types in Visual C++ Pin
Hamid Taebi6-Oct-06 19:31
professionalHamid Taebi6-Oct-06 19:31 
QuestionToo many WM_MOUSEWHEEL events issue Pin
Tnarol5-Oct-06 22:02
Tnarol5-Oct-06 22:02 
QuestionFtpCommand not defined in Visual Studio Pin
codepanter5-Oct-06 21:51
codepanter5-Oct-06 21:51 
AnswerRe: FtpCommand not defined in Visual Studio Pin
benjymous5-Oct-06 21:59
benjymous5-Oct-06 21:59 
GeneralRe: FtpCommand not defined in Visual Studio Pin
codepanter6-Oct-06 0:51
codepanter6-Oct-06 0:51 
GeneralRe: FtpCommand not defined in Visual Studio Pin
David Crow6-Oct-06 2:43
David Crow6-Oct-06 2:43 
AnswerRe: FtpCommand not defined in Visual Studio Pin
Hamid Taebi5-Oct-06 22:04
professionalHamid Taebi5-Oct-06 22:04 
QuestionTo compare two Images to find out the mismatch between them Pin
Dinu_IP5-Oct-06 21:33
Dinu_IP5-Oct-06 21:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.