Procedure NaprimerKakEtoDelaetConsole20otnMarkoBozikovic(Const App:String;AMemo:TMemo);
Const
ReadBuffer = 2400;
Var
Security : TSecurityAttributes;
ReadPipe,WritePipe : THandle;
start : TStartUpInfo;
ProcessInfo : TProcessInformation;
Buffer : PChar;
BytesRead : DWord;
Apprunning : DWord;
Begin
AMemo.Lines.Add('');
Security.nLength:=SizeOf(TSecurityAttributes);
Security.bInheritHandle:=True;
Security.lpSecurityDescriptor:=Nil;
If Createpipe(ReadPipe,WritePipe,@Security,0) Then
Begin
GetMem(Buffer,ReadBuffer+1);
ZeroMemory(@Start,Sizeof(Start));
start.cb :=SizeOf(start);
start.hStdOutput :=WritePipe;
start.hStdInput :=ReadPipe;
start.dwFlags :=STARTF_USESTDHANDLES+STARTF_USESHOWWINDOW;
start.wShowWindow :=SW_HIDE;
If CreateProcess(nil,PChar(App),@Security,@Security,True,NORMAL_PRIORITY_CLASS,Nil, PChar(vtvTempPath+'$DS2\'),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;
OemToAnsi(Buffer,Buffer);
AMemo.Text:=AMemo.Text+String(Buffer);
Until (BytesRead<ReadBuffer);
End;
FreeMem(Buffer);
CloseHandle(ProcessInfo.hProcess);
CloseHandle(ProcessInfo.hThread);
CloseHandle(ReadPipe);
CloseHandle(WritePipe);
End;
End;