1
0
mirror of synced 2024-09-19 17:56:09 +00:00

Visible property toegevoegd aan TProcess

This commit is contained in:
Mark van Renswoude 2009-04-09 10:35:38 +00:00
parent ec1474ee14
commit 34eb23ccff

View File

@ -10,6 +10,7 @@ type
private private
FEnvironment: TStrings; FEnvironment: TStrings;
FCommandLine: String; FCommandLine: String;
FVisible: Boolean;
FWorkingPath: String; FWorkingPath: String;
protected protected
function BuildEnvironment(): String; function BuildEnvironment(): String;
@ -25,6 +26,7 @@ type
property CommandLine: String read FCommandLine write FCommandLine; property CommandLine: String read FCommandLine write FCommandLine;
property Environment: TStrings read FEnvironment; property Environment: TStrings read FEnvironment;
property Visible: Boolean read FVisible write FVisible;
property WorkingPath: String read FWorkingPath write FWorkingPath; property WorkingPath: String read FWorkingPath write FWorkingPath;
end; end;
@ -40,6 +42,7 @@ begin
inherited; inherited;
FEnvironment := TStringList.Create(); FEnvironment := TStringList.Create();
FVisible := False;
FWorkingPath := GetCurrentDir(); FWorkingPath := GetCurrentDir();
end; end;
@ -104,6 +107,9 @@ var
startupInfo: TStartupInfo; startupInfo: TStartupInfo;
writePipe: Cardinal; writePipe: Cardinal;
bytesRead: Cardinal; bytesRead: Cardinal;
newConsole: Boolean;
consoleOutput: THandle;
bytesWritten: Cardinal;
begin begin
Result := False; Result := False;
@ -133,16 +139,34 @@ begin
CloseHandle(writePipe); CloseHandle(writePipe);
writePipe := 0; writePipe := 0;
newConsole := False;
consoleOutput := 0;
if Visible then
begin
newConsole := AllocConsole;
consoleOutput := GetStdHandle(STD_OUTPUT_HANDLE);
end;
try
GetMem(buffer, BufferSize); GetMem(buffer, BufferSize);
try try
repeat repeat
ReadFile(readPipe, buffer^, BufferSize, bytesRead, nil); ReadFile(readPipe, buffer^, BufferSize, bytesRead, nil);
if bytesRead > 0 then if bytesRead > 0 then
begin
AStream.WriteBuffer(buffer^, bytesRead); AStream.WriteBuffer(buffer^, bytesRead);
if consoleOutput <> 0 then
WriteFile(consoleOutput, buffer^, bytesRead, bytesWritten, nil);
end;
until bytesRead = 0; until bytesRead = 0;
finally finally
FreeMem(buffer, BufferSize); FreeMem(buffer, BufferSize);
end; end;
finally
if newConsole then
FreeConsole;
end;
GetExitCodeProcess(processInfo.hProcess, AExitCode); GetExitCodeProcess(processInfo.hProcess, AExitCode);
Result := True; Result := True;