Skip to content

Instantly share code, notes, and snippets.

@robhurring
Created November 22, 2010 20:03
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 robhurring/710569 to your computer and use it in GitHub Desktop.
Save robhurring/710569 to your computer and use it in GitHub Desktop.
Check for piped STDIN in ruby shell scripts without prompting
# 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