-
-
Save zug-zug/2f2e81f4963333542a90ced87595f5bc to your computer and use it in GitHub Desktop.
Why does output for `Open3.capture2e("ruby", <file>)` and `Open3.capture2e(<file>)` differ?
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
#!/usr/bin/ruby | |
=begin | |
This is a simple executable that just parrots what you type back at you, on stdout: | |
$ ./parrot.rb | |
> foo | |
! foo | |
> bar | |
! bar | |
PUZZLE: Why does output for Open3.capture2e("ruby", "./parrot.rb") and Open3.capture2e("./parrot.rb") differ? | |
e.g. ./parrot.rb ### only prints the script's stdout | |
ruby -ropen3 -e 'puts Open3.capture2e("./parrot.rb", stdin_data: "foo\nbar\n").first.inspect' | |
=> "! foo\n! bar\n" | |
e.g. ruby ./parrot.rb ### prints both stdin and stdout | |
ruby -ropen3 -e 'puts Open3.capture2e("ruby", "./parrot.rb", stdin_data: "foo\nbar\n").first.inspect' | |
=> "> foo\n> bar\n> ! foo\n! bar\n" | |
=end | |
require 'readline' | |
loop do | |
cmd = Readline.readline("> ", true) | |
exit if cmd.nil? | |
puts "! #{cmd}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment