Olim
28.04.2009, 07:19
Есть консольная программа, которая создает дочерний процесс перенаправляя хендл стандартного вывода через пайпы. Проблема в том что, если программа выполняется как CGI под Apache то выдается ошибка при чтение данных из созданного пайпа. А если запустить программу как обычно т.е. из эксплора оно работает без ошибок.
Код создания пайпов:
SecureAttr.nLength := SizeOf(SecureAttr);
SecureAttr.lpSecurityDescriptor := nil;
SecureAttr.bInheritHandle := True;
if not CreatePipe(hReadOut, hWriteOut, @SecureAttr, 0) then
raise Exception.Create('Unable to create pipe for compiler''s output');
FillChar(StartInfo, SizeOf(StartInfo), 0);
StartInfo.cb := SizeOf(StartInfo);
StartInfo.wShowWindow := SW_HIDE;
StartInfo.dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;
StartInfo.hStdOutput := hWriteOut;
StartInfo.hStdError := hWriteOut;
if not CreateProcess(PChar(fCompilerPath),
PChar(Format(fCompilerCommand, [fSourceFile])), nil, nil, TRUE,
0, nil, PChar(ExtractFileDir(fSourceFile)),
StartInfo, ProcInfo) then
raise Exception.CreateFmt('Unable to run compiler "%s"', [fCompilerPath]);
if WaitForSingleObject(ProcInfo.hProcess, fCompilationTimeLimit) = WAIT_TIMEOUT then
begin
TerminateProcess(ProcInfo.hProcess, 1);
raise Exception.CreateFmt('Timeout while compiling "%s"', [fSourceFile]);
end;
GetExitCodeProcess(ProcInfo.hProcess, ExitCode);
CloseHandle(hWriteOut);
dwFileSize := GetFileSize(hReadOut, nil);
GetMem(Buffer, dwFileSize);
if (not ReadFile(hReadOut, Buffer^, dwFileSize, dwBytesRead, nil)) or (dwFileSize <> dwBytesRead) then
raise Exception.Create('Unable to read data from compiler''s output pipe');
Buffer^[dwFileSize] := #0;
CloseHandle(hReadOut);
CloseHandle(ProcInfo.hProcess);
CloseHandle(ProcInfo.hThread);
Помогите разобратся!
Код создания пайпов:
SecureAttr.nLength := SizeOf(SecureAttr);
SecureAttr.lpSecurityDescriptor := nil;
SecureAttr.bInheritHandle := True;
if not CreatePipe(hReadOut, hWriteOut, @SecureAttr, 0) then
raise Exception.Create('Unable to create pipe for compiler''s output');
FillChar(StartInfo, SizeOf(StartInfo), 0);
StartInfo.cb := SizeOf(StartInfo);
StartInfo.wShowWindow := SW_HIDE;
StartInfo.dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;
StartInfo.hStdOutput := hWriteOut;
StartInfo.hStdError := hWriteOut;
if not CreateProcess(PChar(fCompilerPath),
PChar(Format(fCompilerCommand, [fSourceFile])), nil, nil, TRUE,
0, nil, PChar(ExtractFileDir(fSourceFile)),
StartInfo, ProcInfo) then
raise Exception.CreateFmt('Unable to run compiler "%s"', [fCompilerPath]);
if WaitForSingleObject(ProcInfo.hProcess, fCompilationTimeLimit) = WAIT_TIMEOUT then
begin
TerminateProcess(ProcInfo.hProcess, 1);
raise Exception.CreateFmt('Timeout while compiling "%s"', [fSourceFile]);
end;
GetExitCodeProcess(ProcInfo.hProcess, ExitCode);
CloseHandle(hWriteOut);
dwFileSize := GetFileSize(hReadOut, nil);
GetMem(Buffer, dwFileSize);
if (not ReadFile(hReadOut, Buffer^, dwFileSize, dwBytesRead, nil)) or (dwFileSize <> dwBytesRead) then
raise Exception.Create('Unable to read data from compiler''s output pipe');
Buffer^[dwFileSize] := #0;
CloseHandle(hReadOut);
CloseHandle(ProcInfo.hProcess);
CloseHandle(ProcInfo.hThread);
Помогите разобратся!