Home > Back-end > Delphi2010 call Windows CMD command line, get back to information for all the code. How to deal with
Delphi2010 call Windows CMD command line, get back to information for all the code. How to deal with
Time:10-08
This code is I found on the Internet, run on delphi7 normal, no noise, but on the d2010 how to debug all not line, please help to check, how to deal with the garbage problem, I search information, the information is d2010 processing Chinese content is 1, 2 is myself, but D7 (the other instructions, this code as if the return value without Chinese, is also the code) Procedure _AddInfo (mmInfo: TMemo; S: a string; Var line: string); Var I, p: Integer; The begin
If mmInfo. Lines. Count & gt; Then 800 MmInfo. Lines. The Clear; For I:=0 to length (S) - 1 do If S [I]=# 13 then S: [I]=' '; Line: line +=S;
P:=Pos (# 10, line); If p & gt; 0 then The begin //mmInfo. Lines. The Add (Copy (line 1, p - 1)); MmInfo. Lines. The Add (Copy (line 1, p - 1)); The line:=Copy (line, p + 1, length (line) - p). end; end;
Procedure CmdExecAndView (FileName: PChar; Memo: TMemo); Var HReadPipe hWritePipe: THandle; Si: STARTUPINFO; Lsa: SECURITY_ATTRIBUTES; PI: PROCESS_INFORMATION; //cchReadBuffer: WCHAR; CchReadBuffer: dword; Ph: PChar; Fname: PChar; Line, readLine: string; The begin Fname:=allocmem (1024); Ph:=allocmem (1024); Lsa. NLength:=SizeOf (SECURITY_ATTRIBUTES); Lsa. LpSecurityDescriptor:=nil; Lsa. BInheritHandle:=true; If CreatePipe (hReadPipe hWritePipe, @ lsa, 0)=False then The Exit; FillChar (si, SizeOf (STARTUPINFO), 0). Si. Cb:=SizeOf (STARTUPINFO); Si. DwFlags:=(STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW); Si. WShowWindow:=SW_HIDE; Si. HStdOutput:=hWritePipe; Si. HStdError:=hWritePipe; StrPCopy (fname, FileName); If CreateProcess (nil, fname, nil nil, true, 0, nil, nil, si, PI)=False then The begin FreeMem (ph); FreeMem (fname); The Exit; end; The CloseHandle (hWritePipe); While (true) do The begin If not PeekNamedPipe (hReadPipe, ph, 1, @ cchReadBuffer, nil, nil) then break; If cchReadBuffer & lt;> 0 then The begin If ReadFile (hReadPipe, ph ^, 4096, cchReadBuffer, nil)=False then break; Ph: [cchReadBuffer]=CRH (0); Memo. Lines. The Add (ph); //_AddInfo (memo, ph, line); End Else if (WaitForSingleObject (PI) hProcess, 0)=WAIT_OBJECT_0) then break; Application. ProcessMessages; Sleep (200); end; Ph: [cchReadBuffer]=CRH (0); Memo. Lines. The Add (ph); //_AddInfo (memo, ph, line); The CloseHandle (hReadPipe); The CloseHandle (PI. HThread); The CloseHandle (PI. HProcess); FreeMem (ph); FreeMem (fname); end;
CodePudding user response:
It depends on what exactly do you perform the procedure returns the character encoding, perhaps the utf-8 and so on