Skip to content

Instantly share code, notes, and snippets.

@robhurring
Created November 22, 2010 20:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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