Bug #3215

Windows: IO.popen returns "handle is invalid"

Added by docwhat (Christian Höltje) over 10 years ago. Updated over 1 year ago.

ruby -v:
ruby 1.9.1p376 (2009-12-07) [x64-mswin64_80]


This is with a VS8 compiled version of ruby.

Given this simple program (foo.rb):
puts "" * 20
p IO.popen('echo HI') {|f| f.readlines}
puts "
" * 20

I get this:
E:\test>bin\ruby.exe foo.rb

The handle is invalid.


Interestingly, if I redirect to a file, it works:
E:\test>bin\ruby.exe foo.rb > q

E:\test>type q



I'm not sure what is going on, but I know that the python group had similar problems in python < 2.6.... maybe we can crib their solution?


Python URLs: -- The patch is interesting.


Updated by rogerdpack (Roger Pack) over 10 years ago

seems to work ok with mingw, if that's any help (which it's not, but still a clue).


Updated by jonforums (Jon Forums) over 10 years ago

When using the mingw v3.4.5 built 1.9.1p378 from the example snippet also works for me (Win7 Ultimate 32-bit) as well as the IO.popen code from the following patch I use with Jekyll


Updated by usa (Usaku NAKAMURA) over 10 years ago

  • Status changed from Open to Feedback
  • Priority changed from Normal to 3

on XP x64, with both of 1.9.1p376 and trunk, I couldn't reproduce it.
Christian, what is your OS?


Updated by docwhat (Christian Höltje) over 10 years ago

It is Windows 2003 Server. I connect via rdesktop. I'm using Visual Studio 8 (aka 2005) to compile ruby. I don't know if it happens with mingw, etc.

If you are able to compile ruby 1.9.1-p376 using VS8, I'd love to swap patches and work-arounds for problems. I've filed bugs for all the obvious ones.


Updated by docwhat (Christian Höltje) over 10 years ago

=begin looks like I can't reliably recreate this. I'm not sure why it works sometimes and not others.


Updated by jeremyevans0 (Jeremy Evans) over 1 year ago

  • Status changed from Feedback to Closed
  • Description updated (diff)

Also available in: Atom PDF