Skip to content

Instantly share code, notes, and snippets.

@JoshCheek
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoshCheek/4e8289ebe5fabd2179ef to your computer and use it in GitHub Desktop.
Save JoshCheek/4e8289ebe5fabd2179ef to your computer and use it in GitHub Desktop.
File to test how fish's redirection works
require 'open3'
def show_printed_for(pipe_code)
out, err, status = Open3.capture3 "fish", stdin_data: <<-PROGRAM
ruby -e '
$stdout.print "outmsg"
$stderr.print "errmsg"
' #{pipe_code} ruby -e '
print "PIPED(\#{$stdin.read})"
'
PROGRAM
puts "OUT: #{out.inspect}"
puts "ERR: #{err.inspect}"
puts
raise 'FAILED!' unless status.success?
end
puts "Normally, err in a pipeline goes to process's err"
show_printed_for "|"
# OUT: "PIPED(outmsg)"
# ERR: "errmsg"
puts "With `^|`, err goes to input of next in pipeline, and out goes to process's out"
show_printed_for "^|"
# OUT: "outmsgPIPED(errmsg)"
# ERR: ""
puts "With `2>&1`, both go to pipe"
show_printed_for "2>&1"
# OUT: "errmsgoutmsg"
# ERR: ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment