Bug #4294
closed
IO.popen ['"ping"', 'localhost -n 3'] fails
Added by redstun (red stun) almost 14 years ago.
Updated over 13 years ago.
Description
=begin
RUBY_VERSION
=> "1.9.2"
RUBY_PLATFORM
=> "i386-mingw32"
IO.popen ['"ping"', 'localhost -n 3']
Errno::EINVAL: Invalid argument - "ping"
from (irb):6:in popen' from (irb):6 from d:/sdks/ruby/ruby-1.9.2-p0-i386-mingw32/bin/irb:12:in
'
tested on both ruby-1.9.2-p0 and ruby-1.9.2-p136
it works if the extra double quotes around 'ping' are removed.
=end
Files
=begin
How is that a bug ? If ping is surrounded by quotes, ruby will look for an executable named "ping" with the quotes around. If ruby starts to magically remove these quotes, I'm not sure it will bring other unwanted side-effect. Buy maybe I missed something. Did it work in 1.8.7 maybe ?
=end
=begin
Perhaps the OP was really concerned about things not on PATH and in dirs with spaces.
FWIW, the following works for me on Win7 32-bit for MRI 1.9.2p160 and 1.9.3dev r30603 (i386-mingw32) but not JRuby 1.6.0.RC1 in --1.9 mode:
IO.popen ['c:\Program Files\7-Zip\7z.exe'] do |i|
puts i.read
end
IIRC 1.8.7 only takes a String rather than an Array of String's
=end
=begin
Right, the case became more obvious when we're running commands whose path contains spaces.
In 1.8.7 IO.popen only support cmd_string, not cmd_array, anyway, the respective form IO.popen '"ping" -n 3 localhost' works, and that works in ruby 1.9.2 too.
=end
=begin
Hello,
In message "[ruby-core:34642] [Ruby 1.9-Bug#4294] IO.popen ['"ping"', 'localhost -n 3'] fails"
on Jan.20,2011 13:49:00, redmine@ruby-lang.org wrote:
Right, the case became more obvious when we're running commands whose path contains spaces.
In 1.8.7 IO.popen only support cmd_string, not cmd_array, anyway, the respective form IO.popen '"ping" -n 3 localhost' works, and that works in ruby 1.9.2 too.
I agree that the difference between the string form and the array
form certainly cofuses us.
But it's the spec of IO.popen.
We must quote the arguments (including command) which contain spaces
at the string form, and must not quote the arguments in any cases
at the array form.
Regards,¶
U.Nakamura usa@garbagecollect.jp
=end
=begin
Thank you Usaku,
I can take what you've said if that's what Ruby Spec has specified.
I just don't know where to find the respective spec,
the ruby-doc[1] doesn't have such words
[1] http://ruby-doc.org/core/classes/IO.html#M000880
=end
=begin
Absolutely agree to Usaku: the whole point of the Array variant of IO.popen is to not need to quote strings. Quoting in the string form is only needed for the implementation to be able to rip arguments properly apart in light of spaces in argument names (any argument, not only the command path!). Quoting is just a crutch. Since that is not needed in the array variant arguments muss be used unchanged (modulo encoding adjustment maybe).
=end
- Category changed from core to doc
- Status changed from Open to Closed
I think current IO.popen should have enough doc.
-
[env, cmdname, arg1, ..., opts] : command name and zero or more arguments (no shell)
"no shell" means you must not quote command name and arguments.
Also available in: Atom
PDF
Like0
Like0Like0Like0Like0Like0Like0Like0Like0