Project

General

Profile

Actions

Bug #4294

closed

IO.popen ['"ping"', 'localhost -n 3'] fails

Added by redstun (red stun) about 13 years ago. Updated almost 13 years ago.

Status:
Closed
Assignee:
-
Target version:
ruby -v:
ruby 1.9.2p136 (2010-12-25) [i386-mingw32]
Backport:
[ruby-core:34610]

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

testproc2.rb (99 Bytes) testproc2.rb redstun (red stun), 01/20/2011 12:54 AM
Actions #1

Updated by zimbatm (zimba tm) about 13 years ago

=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

Actions #2

Updated by jonforums (Jon Forums) about 13 years ago

=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

Actions #3

Updated by redstun (red stun) about 13 years ago

=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

Actions #4

Updated by usa (Usaku NAKAMURA) about 13 years ago

=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, 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

=end

Actions #5

Updated by redstun (red stun) about 13 years ago

=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

Actions #6

Updated by rklemme (Robert Klemme) about 13 years ago

=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

Actions #7

Updated by usa (Usaku NAKAMURA) about 13 years ago

  • Category changed from core to doc

=begin

=end

Actions #8

Updated by naruse (Yui NARUSE) almost 13 years ago

  • 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.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0