Registriert seit: 16. Jan 2005
448 Beiträge
|
cmd output in memo - Bug
28. Jul 2020, 18:42
Hallo Leute,
also in https://delphi.fandom.com/wiki/Captu...altime_To_Memo ist ein super Ansatz,
Delphi-Quellcode:
procedure Tform1.CaptureConsoleOutput(const ACommand, AParameters: String; AMemo: TMemo);
const
CReadBuffer = 2400;
var
saSecurity: TSecurityAttributes;
hRead: THandle;
hWrite: THandle;
suiStartup: TStartupInfo;
piProcess: TProcessInformation;
pBuffer: array[0..CReadBuffer] of Char;
dRead: DWord;
dRunning: DWord;
begin
saSecurity.nLength := SizeOf(TSecurityAttributes);
saSecurity.bInheritHandle := True;
saSecurity.lpSecurityDescriptor := nil;
if CreatePipe(hRead, hWrite, @saSecurity, 0) then
begin
FillChar(suiStartup, SizeOf(TStartupInfo), #0);
suiStartup.cb := SizeOf(TStartupInfo);
suiStartup.hStdInput := hRead;
suiStartup.hStdOutput := hWrite;
suiStartup.hStdError := hWrite;
suiStartup.dwFlags := STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW;
suiStartup.wShowWindow := SW_HIDE;
if CreateProcess(nil, PChar(ACommand + ' ' + AParameters), @saSecurity,
@saSecurity, True, NORMAL_PRIORITY_CLASS, nil, nil, suiStartup, piProcess)
then
begin
repeat
dRunning := WaitForSingleObject(piProcess.hProcess, 100);
Application.ProcessMessages();
repeat
dRead := 0;
ReadFile(hRead, pBuffer[0], CReadBuffer, dRead, nil);
pBuffer[dRead] := #0;
OemToAnsi(pBuffer, pBuffer);
AMemo.Lines.Add(String(pBuffer));
until (dRead < CReadBuffer);
until (dRunning <> WAIT_TIMEOUT);
CloseHandle(piProcess.hProcess);
CloseHandle(piProcess.hThread);
end;
CloseHandle(hRead);
CloseHandle(hWrite);
end;
end;
doch leider bekomme ich in zeile
if CreatePipe(hRead, hWrite, @saSecurity, 0) then
Diesen Error:
[dcc64 Fehler] BUnit1.pas(1313): E2010 Inkompatible Typen: 'PAnsiChar' und 'array[0..2400] of Char'
Ich kenne mich nicht ganz aus, es sit pBuffer ja ein array of Char, und das CretePipe braucht PChar.
Wie kann man den Fehler beheben? Ich habe Delphi Berlin.
DANKE
|
|
Zitat
|