🏭
Open3の使い方チートシート風まとめ
Ruby の Open3モジュール はメソッド名と機能の対応がわかりにくいので自分用にまとめた。
| 戻値 | Method | stdin_data | binmode | 2>&1 | block | |
|---|---|---|---|---|---|---|
| ◎ | stdin, stdout, stderr, thread | popen3 | ○ | |||
| stdin, stdout_or_stderr, thread | popen2e | ○ | ○ | |||
| 🞨 | stdin, stdout, thread | popen2 | ○ | |||
| ○ | body, error_body, status | capture3 | ○ | ○ | ||
| body, status | capture2e | ○ | ○ | ○ | ||
| 🞨 | body, status | capture2 | ○ | ○ |
| 戻値 | Method | block |
|---|---|---|
| statuses | pipeline | |
| threads | pipeline_start | ○ |
| stdout, threads | pipeline_r | ○ |
| stdin, stdout, threads | pipeline_rw | ○ |
| stdin, threads | pipeline_w | ○ |
| column | 意味 |
|---|---|
| 戻値 | ブロック対応の場合は同じ並びで受け取れる |
| stdin_data | stdin_data: "xxx" で入力を渡せる |
| binmode | binmode: true でバイナリモードになる |
| 2>&1 | エラー出力を標準出力とする |
| block | ブロックに対応している |
| pipeline* の引数のタイプ |
|---|
| commandline |
| [commandline, options] |
| [env, commandline, options] |
| [env, cmdname, arg1, arg2, ..., options] |
| [env, [cmdname, argv0], arg1, ..., options] |
- 基本
popen3だけ使っていればなんら問題ない - そこで標準入力を渡すのに複数行書くのが耐えられないとなったら
capture3を使う -
2>&1の表記も耐えられないとなったらeで終わるメソッド使う -
2で終わるメソッドはエラーを見なかったふりするようなものなので忘れていい - pipeline* のことも全部忘れていい
Discussion