[Rake-devel] Question about system call and multiple arguments.

Jim Weirich jim.weirich at gmail.com
Sat Nov 1 15:24:17 EDT 2008

On Nov 1, 2008, at 12:26 PM, Luis Lavena wrote:

> I'm trying to find the real problem about the implementation of
> system(...) call for this test:
> http://github.com/jimweirich/rake/tree/master/test/test_fileutils.rb#L214-240
>      # This one does not get expanded
>      block_run = false
>      ruby '-e', %{exit "#{env_var}".length} do |ok, status| #  
> " (emacs wart)
>        assert(!ok)
>        assert_equal 15, status.exitstatus
>        block_run = true
>      end
>      assert block_run, "The block must be run"
> ==
> I just verified the output of the command being generated:
> ruby -e exit "$RAKE_TEST_RUBY".length
> And tested that on linux:
> http://pastie.org/private/b7cdjijfgrt1j518cdlosa
> As you can see, the lack of quotes around the command for -e option is
> generating the issue.
> Did I miss something?
> Thanks in advance for your time, I'm looking forward find the issue
> behind this to properly patch ruby if required.

It's not a command line issue.  It is how the system command works in  
Ruby.  Here is the expected semantics:

$ irb
 >> system "echo $HOME"
=> true
 >> system "echo", "$HOME"
=> true

A single string argument to system will be expanded by the shell (i.e.  
$HOME is translated to "/Users/jim").

When multiple strings are passed to system, they are not expanded by  
the shell. (i.e. "$HOME" remains unchanged).

The tests are trying to verify that the rake methods "sh" and "ruby"  
exhibit the same behavior as the built-in system method.

I guess my question is:

1) When using system on Windows, do you get the same behavior as above  
(possibly substituing "%HOME%" for "$HOME")?

2) If you get different behavior, what should Rake do about it.

-- Jim Weirich
-- jim.weirich at gmail.com

More information about the Rake-devel mailing list