Created
November 22, 2010 20:03
-
-
Save robhurring/710569 to your computer and use it in GitHub Desktop.
Check for piped STDIN in ruby shell scripts without prompting
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
# body will be set ONLY if data is piped in, and will not | |
# prompt the user for STDIN otherwise. | |
require 'fcntl' | |
body = STDIN.read if STDIN.fcntl(Fcntl::F_GETFL, 0) == 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment