Skip to content

Instantly share code, notes, and snippets.

@mariash
Created October 4, 2012 00:24
Show Gist options
  • Save mariash/3830763 to your computer and use it in GitHub Desktop.
Save mariash/3830763 to your computer and use it in GitHub Desktop.
ruby popen fds
open('/tmp/f','w'){|f| f << 'sekrit'}
f = open('/tmp/f')
exec("ruby -e 'p IO.open(#{f.fileno}).read'")
# Prints 'sekrit'
open('/tmp/f','w'){|f| f << 'sekrit'}
f = open('/tmp/f')
IO.popen("ruby -e 'p IO.open(#{f.fileno}).read'")
# Fails 'Bad file descriptor'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment