本文へ移動
Hikari リファレンス

std:process リファレンス

import process := "std:process" で取得するサブプロセス実行モジュール。外部コマンドの実行 (exec / run / run_opts) を提供する。

exec

exec(argv)
exec: { List(String) | Effect(Future(Result({ code: Int, stdout: String, stderr: String |}, ProcError)), Proc) }

argv を shell を介さず直接起動する (注入安全)。

効果ハンドラーの操作である。handle の操作スロットに exec と書いて横取りできる(language-spec.md §17.9)。

>>> result := process.exec(["echo", "hi"])!
>>> print result

run

run(cmd)
run: { String | Effect(Future(Result({ code: Int, stdout: String, stderr: String |}, ProcError)), Proc) }

cmd を shell 経由 (sh -c) で実行する。exit 0 は Ok、非 0 は Err。

効果ハンドラーの操作である。handle の操作スロットに run と書いて横取りできる(language-spec.md §17.9)。

>>> result := process.run("echo hi")!
>>> print result

run_opts

run_opts(opts)
run_opts: { Any | Effect(Future(Result({ code: Int, stdout: String, stderr: String |}, ProcError)), Proc) }

opts で cmd|argv / cwd / env / env_remove / stdin / stdio を指定して実行する。env_remove は継承した環境から落とす名前の List (空文字を入れても落ちない)。stdio := \"inherit\" は親の標準入出力へ直結する (ライブ出力・対話用。既定 \"capture\")。

効果ハンドラーの操作である。handle の操作スロットに run_opts と書いて横取りできる(language-spec.md §17.9)。

>>> process.run_opts({ argv := ["ls", "-l"], cwd := "/tmp" |})!
>>> process.run_opts({ cmd := "go test ./...", stdio := "inherit" |})!