[출처 : http://delphi.borlandforum.com/impboard/impboard.dll?action=read&db=del_tip&no=148 - 임프(박지훈) 님 글]
- procedure TForm1.Button1Click(Sender: TObject);
- var
- start: TStartupInfo;
- sec: TSecurityAttributes;
- pinfo: TProcessInformation;
- hwrite, hread: THandle;
- BytesRead: DWORD;
- Buffer: array[0..512] of char;
- ResultString: string;
- begin
- sec.nLength := sizeof(sec);
- sec.lpSecurityDescriptor := nil;
- sec.bInheritHandle := true;
-
-
- if CreatePipe(hread, hwrite, @sec, 0)<>true then
- begin
- ShowMessage('Fail to open pipe.');
- exit;
- end;
-
-
- FillChar(start, sizeof(STARTUPINFO), 0);
- start.cb := sizeof(start);
- start.dwFlags := STARTF_USESTDHANDLES;
- start.hStdOutput := hwrite;
- start.hStdError := hwrite;
-
-
- if CreateProcess(nil, 'dcc32.exe', nil, nil, true, DETACHED_PROCESS, nil, nil, start, pinfo) <> true then
- begin
- ShowMessage(AnsiString('CreateProcess() failed: ') + IntToStr(GetLastError));
- exit;
- end;
-
- CloseHandle(hwrite);
-
- while ReadFile(hread, Buffer, Length(buffer)-1, BytesRead, nil) and (BytesRead>0) do
- begin
- Buffer[BytesRead] := #0;
- ResultString := ResultString + Buffer;
-
-
-
-
-
-
- end;
- CloseHandle(hread);
-
- Memo1.Lines.Text := ResultString;
- end;
트랙백 주소 - http://skyrack.tistory.com/trackback/147