PDA

View Full Version : Console Capture in Windows NT



Andreaz
05-12-2002, 07:59 AM
Im writing on a javaeditor in delphi and want's to capture the output from the javac compiler in WindowsNT, but i cant capture it, i use the function below to capture it, it works with other dos apps such as the Digital Mars C/C++ Compiler or format but not with the java jdk. Know that this has something to do with the way the jdk writes to the screen but don't know how to solve it ?


procedure RunDosApp(DosApp: String; var Strings: TStringList);
const ReadBuffer = 2600;
var CursorPos: TCoord;
var
Security : TSecurityAttributes;
ReadPipe,WritePipe : THandle;
start : TStartUpInfo;
ProcessInfo : TProcessInformation;
Buffer : Pchar;
BytesRead : DWord;
Apprunning : DWord;
begin
CursorPos.x := 0;
CursorPos.y := 0;
With Security do begin
nlength := SizeOf(TSecurityAttributes);
binherithandle := true;
lpsecuritydescriptor := nil;
end;
if Createpipe (ReadPipe, WritePipe,
@Security, 0) then begin
Buffer := AllocMem(ReadBuffer + 1);
FillChar(Start,Sizeof(Start),#0);
start.cb := SizeOf(start);
start.hStdOutput := WritePipe;
start.hStdInput := ReadPipe;
start.dwFlags := STARTF_USESTDHANDLES +
STARTF_USESHOWWINDOW;
start.wShowWindow := SW_HIDE;

if CreateProcess(nil,
PChar(DosApp),
@Security,
@Security,
true,
NORMAL_PRIORITY_CLASS,
nil,
nil,
start,
ProcessInfo)
then
begin
repeat
Apprunning := WaitForSingleObject(ProcessInfo.hProcess,100);
Application.ProcessMessages;
until (Apprunning <> WAIT_TIMEOUT);
Repeat
BytesRead := 0;

ReadFile(ReadPipe,Buffer[0], ReadBuffer, BytesRead,nil);
Buffer[BytesRead]:= #0;
OemToChar(Buffer,Buffer);
Strings.Text := Strings.text + String(Buffer);
until (BytesRead < ReadBuffer);
end;
FreeMem(Buffer);
CloseHandle(ProcessInfo.hProcess);
CloseHandle(ProcessInfo.hThread);
CloseHandle(ReadPipe);
CloseHandle(WritePipe);
end;
end;