Last active
August 29, 2015 14:12
-
-
Save JoshCheek/4e8289ebe5fabd2179ef to your computer and use it in GitHub Desktop.
File to test how fish's redirection works
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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