📄 列表6.6.txt
字号:
【列表6.6】摘录自PipeReadMain.pas的程序代码。
procedure TPipeReadMainForm. RunPSBtnClick(Sender: TObject);
const
LF = ^J; { ASCII linefeed/newline }
READ_IOMode : 'r'; { read mode from pipe }
var
CmdArr : array[0..512] of char;
StrArr : array[0..1024] of char;
F : PIOFile;
pPipeStr : Pointer;
s : String;
begin
psMemo.Clear;
{ Set up to run the ps command }
StrCopy(CmdArr, 'ps');
if ParamCombo.ItemIndex > 0
then begin
{ Add a selected parameter }
s :=' ', + ParamCombo. Items[ParamCombo. ItemIndex];
StrPCopy(StrArr, s);
StrCat(CmdArr, StrArr);
end;
{ Open a pipe for reading from ps's output }
F := popen(CmdArr, READ_IOMode);
if assigned(F)
then begin
repeat
{ Read a complete line from the ps output stream }
pPipeStr := fgets(StrArr, 1024, F);
if Assigned(pPipeStr)
then begin
s := StrPas(pPipeStr);
if pos(LF, s) > 0 then delete(s, pos(LF, s), 1);
psMemo. Lines.Add(s);
end;
until not Assigned(pPipeStr);
{ Close the pipe - don't try to catch errors }
pclose(F);
end;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -