function TEventThread.RunCaptured(
const _dirName, _exeName,
_cmdLine:
string): Boolean;
var
Start: TStartupInfo;
procInfo: TProcessInformation;
tmpName:
string;
tmp: THandle;
tmpSec: TSecurityAttributes;
res: TStringList;
return: Cardinal;
begin
Result := False;
try
{ Setze ein Temporäres File }
{ Set a temporary file }
tmpName := '
Test.tmp';
FillChar(tmpSec, SizeOf(tmpSec), #0);
tmpSec.nLength := SizeOf(tmpSec);
tmpSec.bInheritHandle := True;
tmp := CreateFile(PChar(tmpName), GENERIC_WRITE, File_Share_Write, @tmpSec,
Create_Always, FILE_ATTRIBUTE_NORMAL, 0);
try
FillChar(Start, SizeOf(Start), #0);
Start.cb := SizeOf(Start);
Start.hStdOutput := tmp;
Start.dwFlags := StartF_UseStdHandles
or StartF_UseShowWindow;
Start.wShowWindow := SW_Minimize;
{ Starte das Programm }
{ Start the program }
if CreateProcess(
nil, PChar(_exeName + '
' + _cmdLine),
nil,
nil, True,
CREATE_NO_WINDOW,
nil, PChar(_dirName), Start, procInfo)
then
begin
SetPriorityClass(procInfo.hProcess, Idle_Priority_Class);
WaitForSingleObject(procInfo.hProcess, Infinite);
GetExitCodeProcess(procInfo.hProcess, return);
Result := (return = 0);
CloseHandle(procInfo.hThread);
CloseHandle(procInfo.hProcess);
CloseHandle(tmp);
{ Die Ausgaben hinzufügen }
{ Add the output }
res := TStringList.Create;
try
res.LoadFromFile(tmpName);
MInfo.Clear;
MInfo := res;
// AUSGABE!!!
Log(True, '
INFORMATION: Count of res = ' + IntToStr(res.Count) + '
!');
Log(True, '
INFORMATION: Count of MInfo = ' +
IntToStr(MInfo.Count) + '
!');
// Anzahl der Zeilen in LogDatei speichern
finally
res.Free;
end;
DeleteFile(PChar(tmpName));
end
else
begin
Log(True, '
ERROR: ' + PChar(SysErrorMessage(GetLastError())));
end;
except
on E:
Exception do
begin
Log(True, Format('
ERROR: [%s] "%s"', [E.Classname, E.
Message]));
CloseHandle(tmp);
DeleteFile(PChar(tmpName));
end;
end;
finally
end;
end;