(I thought this should, perhaps, be in the General Help category, but it seems I cannot create a new topic there)
I have this console app that is started from a GUI app, historically it is passed parameters in the command line and writes to std out which is read by the GUI app when the console app finishes.
Due to changes I need to write to the app as it is running, and I chose to do that by getting the app to read StdIn, after checking that something is available to be read.
Running from the command line, this updated app works just fine.
Running from the GUI it crashes with System Error 6 as soon as it tries to read stdin. The stdin handle is not nul.
This is the creation code, roughly.
with SA do begin
nLength := SizeOf(SA);
bInheritHandle := True;
lpSecurityDescriptor := nil;
end;
CreatePipe(StdInPipeRead[curtask], StdInPipeWrite[curtask], @SA, 0);
CreatePipe(StdOutPipeRead[curtask], StdOutPipeWrite[curtask], @SA, 0);
with SI[curtask] do
begin
FillChar(SI[curtask], SizeOf(SI[curtask]), 0);
cb := SizeOf(SI[curtask]);
dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;
wShowWindow := SW_HIDE;
hStdInput := StdInPipeRead[curtask];
hStdOutput := StdOutPipeWrite[curtask];
hStdError := StdOutPipeWrite[curtask];
end;
Handle[curTask] := CreateProcess(nil, PChar(Cmd + ' '),
@SI[curTask], @SI[curTask], {nil, nil,} True, CREATE_NEW_CONSOLE or SYNCHRONIZE{0}, nil,
nil, SI[curTask], PI[curTask]);
CloseHandle(StdOutPipeWrite[curTask]); // doesn't matter if commented out
CloseHandle(StdInPipeRead[curTask]); // doesn't matter if commented out
Any ideas as to what is wrong?