1,183
社区成员
发帖
与我相关
我的任务
分享
function TForm1.ReadFromPipe(Pipe: THandle): string;
var
Buffer: array[1..32767] of AnsiChar;
BytesRead: DWord;
aStr: AnsiString;
begin
Result := '';
if GetFileSize(Pipe, nil) = 0 then
Exit;
repeat
BytesRead := 0;
ReadFile(Pipe, Buffer, SizeOf(Buffer), BytesRead, nil);
if BytesRead > 0 then
begin
aStr := AnsiString(Buffer); //Buffer里面装的是Ansi字符
SetLength(aStr, BytesRead);
Result := Result + String(aStr);
end;
until (BytesRead < SizeOf(Buffer));
end;
procedure TForm1.WriteToPipe(Pipe: THandle; Value: string);
var
BytesWrite: DWord;
aStr: AnsiString;
begin
aStr := AnsiString(Value + #13#10);;
WriteFile(Pipe, aStr[1], Length(aStr), BytesWrite, nil); //发给console的命令应该是AnsiString
end;