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

CodePudding user response:

reference 1st floor aqtata response:
it depends on what exactly do you perform the procedure returns the character encoding, perhaps like utf-8


What do you think return character encoding?

I test is a simple echo of the code

CodePudding user response:

Batch replacement
The String is replaced by AnsiString
Replace for PAnsiChar PChar

CodePudding user response:

The
reference 3 floor pathletboy response:
batch replacement
The String is replaced by AnsiString
PChar replaced with PAnsiChar

Don't need to be replaced.
In unit topped with a
Type
String=ansistring;
Pchar=pansichar;
Can be

CodePudding user response:

reference 4 floor wr960204 response:
Quote: reference pathletboy reply: 3/f

Batch replacement
The String is replaced by AnsiString
PChar replaced with PAnsiChar

Don't need to be replaced.
In unit topped with a
Type
String=ansistring;
Pchar=pansichar;
Can

Pchar can do it, not string

CodePudding user response:

reference 5 floor pathletboy reply:
Quote: refer to 4th floor wr960204 response:

Quote: refer to the third floor pathletboy response:

Batch replacement
The String is replaced by AnsiString
PChar replaced with PAnsiChar

Don't need to be replaced.
In unit topped with a
Type
String=ansistring;
Pchar=pansichar;
Can

Pchar can do it, not the string

Ok you know tried

CodePudding user response:

refer to 6th floor wr960204 response:
Quote: refer to the fifth floor pathletboy reply:

Quote: refer to 4th floor wr960204 response:

Quote: refer to the third floor pathletboy response:

Batch replacement
The String is replaced by AnsiString
PChar replaced with PAnsiChar

Don't need to be replaced.
In unit topped with a
Type
String=ansistring;
Pchar=pansichar;
Can

Pchar can do it, not the string

Ok you try to know


Of course tried to reply,

CodePudding user response:

Wait for can or not

CodePudding user response:

Type
String=ansistring;

This is not possible, the string is a reserved word, reserved words how can redefine, not c/c + +

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related