임프랍니다.
원래 소스를 작성하신 분이 Win32 API를 잘 이해하지 못하고 작성하신 것 같군요.
일단, 소스 자체에서는, 내부에서 사용하고 있는 UsingWinNT를 true로 설정해줘야 하는 거였습니다.
하지만.. CreatePipe()를 호출할 때 SecurityAttributes 인자가 NT와 95계열에서 다른 것은 맞지만,
그냥 SecurityAttributes 객체를 넘겨주면 됩니다. 95계열의 경우 이 인자를 무시하니까요.
또 이걸 꼭 InitializeSecurityDescriptor()를 호출해서 초기화해줄 필요도 없습니다.
그냥 구조체 자체만 초기화하면 되죠.
그 외에도 불필요한 코드가 너무 많아서, 싹 지워버리고 필요한 것만 남겨서 재구성했습니다.
소스 길이가 거의 반 정도로 줄어들었습니다. ^^;;
참고로, 이것은 여기 C++Builder 팁 게시판에도 이전에 올렸던 것입니다. C++ 코드이긴 합니다만.
http://www.borlandforum.com/impboard/impboard.dll?action=read&db=bcb_tip&no=173
function RunDosCommand(Command : string): string;
var
hReadPipe, hWritePipe: THandle;
SI: TStartUpInfo;
PI: TProcessInformation;
SA: TSecurityAttributes;
BytesRead: DWORD;
Dest: array[0..1023] of char;
begin
SA.nLength := SizeOf(TSecurityAttributes);
SA.lpSecurityDescriptor := nil;
SA.bInheritHandle := True;
CreatePipe(hReadPipe, hWritePipe, @SA, 1024);
FillChar(SI, SizeOf(SI), 0);
SI.cb := SizeOf(TStartUpInfo);
SI.dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;
SI.hStdOutput := hWritePipe;
SI.hStdError := hWritePipe;
if CreateProcess(nil, PChar(Command), nil, nil, True, NORMAL_PRIORITY_CLASS, nil, nil, SI, PI)=false then
exit;
CloseHandle(hWritePipe);//이것을 하지 않으면 프로세스가 block된다
while ReadFile(hReadPipe, Dest, 1024, BytesRead, nil) and (BytesRead>0) do
begin
result := result + StrPas(Dest);
{if GetAsyncKeyState(VK_ESCAPE)<0 then break; // 실행에 많은 시간이 걸릴 경우 주석해제 필요
Application.ProcessMessages;}
end;
CloseHandle(hReadPipe);
end;
그럼 이만...