⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 列表6.6.txt

📁 klinux书籍的配套光盘。可以学习学习。
💻 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 + -