Created
July 24, 2013 16:55
-
-
Save timuruski/6072363 to your computer and use it in GitHub Desktop.
Trying to tease out STDIN/OUT interactivity for Ruby scripts
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
puts "STDIN: #{STDIN.tty?}, $stdin: #{$stdin.tty?}" | |
puts "STDOUT: #{STDOUT.tty?}, $stdout: #{$stdout.tty?}" |
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/env bash | |
ruby test.rb |
$ ruby test.rb
> STDIN: true, $stdin: true
> STDOUT: true, $stdout: true
$ ruby test.rb | cat
> STDIN: true, $stdin: true
> STDOUT: false, $stdout: false
$ echo | ruby test.rb | cat
STDIN: false, $stdin: false
STDOUT: false, $stdout: false
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try running the Ruby script directly, the shell script and running it through a
bash
invocation and sub-shell, the value oftty?
is always true.