Hàng sưu tầm, các bác tham khảo thử: Mã: type TArg<T> = reference to procedure(const Arg: T); private { Private declarations } procedure CaptureConsoleOutput(const ACommand, AParameters: String; CallBack: TArg<PAnsiChar>); procedure TForm1.CaptureConsoleOutput2(const ACommand, AParameters: String; CallBack: TArg<PAnsiChar>); const CReadBuffer = 2400; var saSecurity: TSecurityAttributes; hRead: THandle; hWrite: THandle; suiStartup: TStartupInfo; piProcess: TProcessInformation; pBuffer: array [0 .. CReadBuffer] of AnsiChar; dBuffer: array [0 .. CReadBuffer] of AnsiChar; dRead: DWORD; dRunning: DWORD; dAvailable: DWORD; begin saSecurity.nLength := SizeOf(TSecurityAttributes); saSecurity.bInheritHandle := true; saSecurity.lpSecurityDescriptor := nil; if CreatePipe(hRead, hWrite, @saSecurity, 0) then try 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 try repeat dRunning := WaitForSingleObject(piProcess.hProcess, 100); PeekNamedPipe(hRead, nil, 0, nil, @dAvailable, nil); if (dAvailable > 0) then repeat dRead := 0; ReadFile(hRead, pBuffer[0], CReadBuffer, dRead, nil); pBuffer[dRead] := #0; OemToCharA(pBuffer, dBuffer); CallBack(dBuffer); until (dRead < CReadBuffer); Application.ProcessMessages; until (dRunning <> WAIT_TIMEOUT); finally CloseHandle(piProcess.hProcess); CloseHandle(piProcess.hThread); end; finally CloseHandle(hRead); CloseHandle(hWrite); end; end; Mã: Memo2.Lines.Clear; Memo2.Lines.Add('IMEI... '); CaptureConsoleOutput('util.exe '+Edit5.text+' '+ Edit7.text,'', procedure(const Line: PAnsiChar) begin Memo2.Lines.Add(String(Line)); Memo2.Lines.Add(' '); end ); Memo2.Lines.Add('Reversing'); RenameFile('MP0B_001_NEW', 'MP0B_001'); Memo2.Lines.Add(''); CaptureConsoleOutput('adb.exe push MP0B_001 /data/nvram/md/NVRAM/NVD_IMEI/MP0B_001','', procedure(const Line: PAnsiChar) begin Memo2.Lines.Add(String(Line)); Memo2.Lines.Add(' '); end ); CaptureConsoleOutput('adb.exe reboot','', procedure(const Line: PAnsiChar) begin Memo2.Lines.Add(String(Line)); Memo2.Lines.Add(' '); end ); Memo2.Lines.Add('Done : )');