Project

General

Profile

Actions

Bug #1304

closed

Kernel#system bug

Added by Borislav (Borislav Stanimirov) about 15 years ago. Updated almost 13 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
1.9.1p0
Backport:
[ruby-core:22960]

Description

=begin
To reproduce on Windows:
Create a batch file with one argument in a folder that has a space in its name. In Ruby call:
system('"c:\your full path\batchfile.bat" yourparam')

It will behave as if the quotations are missing. (Error: c:\your is not recognized as a command...)
=end

Actions #1

Updated by nobu (Nobuyoshi Nakada) about 15 years ago

=begin
Hi,

At Fri, 20 Mar 2009 02:42:11 +0900,
Borislav Stanimirov wrote in [ruby-core:22960]:

To reproduce on Windows:
Create a batch file with one argument in a folder that has a space in its name. In Ruby call:
system('"c:\your full path\batchfile.bat" yourparam')

It will behave as if the quotations are missing. (Error: c:\your is not recognized as a command...)

It can't reproduce.

$ cat "tmp/foo bar/test.bat"
echo %0 %*

$ ./i386-mswin32/ruby -v -e 'bat=File.expand_path(ARGV[0]).tr("/", "\"); p system(%["#{bat}" 1 2 3])' "tmp/foo bar/test.bat"
ruby 1.9.1p0 (2009-03-04 revision 22762) [i386-mswin32]
c:\Users\nobu\src\ruby\ruby-1.9.1>echo "c:\Users\nobu\src\ruby\ruby-1.9.1\tmp\foo bar\test.bat" 1 2 3
"c:\Users\nobu\src\ruby\ruby-1.9.1\tmp\foo bar\test.bat" 1 2 3
true

--
Nobu Nakada

=end

Actions #2

Updated by nobu (Nobuyoshi Nakada) about 15 years ago

  • Status changed from Open to Feedback

=begin

=end

Actions #3

Updated by daz (Dave B) about 15 years ago

=begin

puts RUBY_DESCRIPTION
#=> ruby 1.9.1p0 (2009-01-30 revision 21907) [i386-mswin32_90]

system('"C:\Documents and Settings\batchfile.bat" myparam')

(No problem)

daz

=end

Actions #4

Updated by Borislav (Borislav Stanimirov) about 15 years ago

=begin
I am sorry that I mislead you. It turns out that the parameter needs to be in quoutations too (as if it's another file with a space in it)

my exact test case:

BackwardCopy.cmd:
@copy %2 %1

Test.rb:
system('"C:\New Folder\BackwardCopy.cmd" "C:\New Folder\target.txt" "C:\New Folder\source.txt"')

So I tested it some more and if the arguments have no quoutations it works ok. Here is an even simpler case that reproduces the bug:

Test.cmd:
echo %1 %2

Test.rb:
system('"C:/New Folder/test.cmd" "a" b') #=>'C:/New' is not recognized as an internal or external command,
operable program or batch file.
#system('"C:/New Folder/test.cmd" a b') works

=end

Actions #5

Updated by phasis68 (Heesob Park) about 15 years ago

=begin
According to the document of CreateProcess (http://msdn.microsoft.com/en-us/library/ms682425.aspx) :
To run a batch file, you must start the command interpreter; set lpApplicationName to cmd.exe and set lpCommandLine to the following arguments: /c plus the name of the batch file.

Here is a quick patch:
--- win32.c 2009-01-16 00:37:20.000000000 +0900
+++ win32.c.new 2009-03-20 19:08:24.000000000 +0900
@@ -1002,6 +1002,10 @@
command_found:
shell = p;
translate_char(p, '/', '\');

  • if(stricmp(shell+strlen(shell)-4,".bat")==0 ||

  •     stricmp(shell+strlen(shell)-4,".cmd")==0)  {
    
  •     shell = NULL;
    
  •   }
    

    }

    return child_result(CreateChild(cmd, shell, NULL, NULL, NULL, NULL), mode);

=end

Actions #6

Updated by nobu (Nobuyoshi Nakada) about 15 years ago

  • Status changed from Feedback to Closed
  • % Done changed from 0 to 100

=begin
Applied in changeset r23023.
=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0