第 6 章

进程与系统

运行命令、消费输出并检查系统状态。

安全运行命令

example.hhy
run(["git", "log", "--oneline"], { timeout: 5s })
    |> stdout_lines
    |> take(10)
    |> print

run 默认直接传递 argv,不经过 Shell。options 支持 cwd、env、stdin、timeout 与 max_output;stdout_lines 将输出转成惰性行流。

系统数据

  • processes:进程快照流
  • system:操作系统、架构、CPU 与内存元数据
  • env:环境变量只读视图
  • shell:显式选择 Shell 语义,不与 run 混用