Skip to content

Instantly share code, notes, and snippets.

@matti
Created June 23, 2017 08:14
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matti/7e44cd9ebfb75bc5e0a89ef33a09b594 to your computer and use it in GitHub Desktop.
Save matti/7e44cd9ebfb75bc5e0a89ef33a09b594 to your computer and use it in GitHub Desktop.
Separates Ruby PTY spawn stderr from stdout
require "pty"
stderr_reader, stderr_writer = IO.pipe
args = ["-c", "read a; echo was: $a; echo err:$a >&2"]
stdout,stdin,pid = PTY.spawn("/bin/bash", *args, err: stderr_writer.fileno)
stderr_writer.close
stdin.puts "hello"
puts stdout.read
puts stderr_reader.read
@pre
Copy link

pre commented Sep 7, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment