Module: Polyrun::ProcessStdio
- Defined in:
- lib/polyrun/process_stdio.rb
Overview
Run a subprocess without Open3 pipe reader threads (avoids noisy IOErrors on SIGINT when streams close). By default stdin/stdout/stderr are inherited so output streams live and the child can use the TTY for prompts.
Constant Summary collapse
- MAX_FAILURE_CAPTURE_BYTES =
32_768
Class Method Summary collapse
-
.format_failure_message(label, status, stdout, stderr) ⇒ Object
Builds a diagnostic string for failed subprocesses (used when silent: true hid live output).
- .inherit_stdio_spawn_wait(env, *argv, chdir: nil, silent: false) ⇒ Process::Status
-
.spawn_wait(env, *argv, chdir: nil, silent: false) ⇒ Array(Process::Status, String, String)
Like #inherit_stdio_spawn_wait, but returns captured stdout/stderr when
silentis true.
Class Method Details
.format_failure_message(label, status, stdout, stderr) ⇒ Object
Builds a diagnostic string for failed subprocesses (used when silent: true hid live output).
34 35 36 37 38 39 40 41 |
# File 'lib/polyrun/process_stdio.rb', line 34 def (label, status, stdout, stderr) msg = "#{label} failed (exit #{status.exitstatus})" s = stdout.to_s e = stderr.to_s msg << "\n--- stdout ---\n#{s}" unless s.strip.empty? msg << "\n--- stderr ---\n#{e}" unless e.strip.empty? msg end |
.inherit_stdio_spawn_wait(env, *argv, chdir: nil, silent: false) ⇒ Process::Status
16 17 18 19 |
# File 'lib/polyrun/process_stdio.rb', line 16 def inherit_stdio_spawn_wait(env, *argv, chdir: nil, silent: false) st, = spawn_wait(env, *argv, chdir: chdir, silent: silent) st end |
.spawn_wait(env, *argv, chdir: nil, silent: false) ⇒ Array(Process::Status, String, String)
Like #inherit_stdio_spawn_wait, but returns captured stdout/stderr when silent is true. On success those strings are empty (not read). When silent is false, output goes to the TTY and returned captures are empty.
26 27 28 29 30 31 |
# File 'lib/polyrun/process_stdio.rb', line 26 def spawn_wait(env, *argv, chdir: nil, silent: false) args = spawn_argv(env, *argv) return spawn_wait_inherit(args, chdir) unless silent spawn_wait_silent(args, chdir) end |