On Jan 6, 2008 3:14 PM, JJ <jjnoakes / gmail.com> wrote:
> I was reading about Kernel::exec (and the related Kernel::system
> function and %x operator).
>
> These routines follow the Perl-ish idiom, which is "If there is one
> argument, pass it to the shell; if there is more than one argument,
> execute it directly". I call it the Perl-ish idiom simply because that
> is the first place I saw this one-exec-routine-to-serve-them-all
> behavior.
>
> Now, there is a serious limitation to this, which exists on all
> platforms that allow shell meta-characters in file names (space,
> asterisk, etc). I usually come across the bug when running
> applications on Windows. The problem is this:
>
>   exec("C:\\Program Files\\Anything\\Foo.exe");
>
> Since this is a one-argument call to Kernel::exec, Ruby passes it to
> the command interpreter, which tries to split the single argument on
> shell meta-characters as it would for "echo *" or "ls -al". However,
> "C:\\Program" is not the executable that we desire.
>
> In Perl, one can force the no-shell-interpreter path by calling exec
> (and system) like so:
>
>   my $cmd = "C:\\Program Files\\...";
>   exec( { $cmd } $cmd );
>
> Is there any such option in Ruby?
>
> -JJ
>

Try this convolution:

exec('start "" "C:\Program Files\Anything\Foo.exe" ')

[Tested with exec and `` in irb and ruby -e'...']

Using "start" involves some special option parsing in the shell. This
only works with the one-argument form of the exec call, since "start"
is a shell built-in. You have to include the blank argument (window
title override - ignored (I think) when there's no interactive command
shell window).

I believe this works with any path permitted under Windows. AND, it
will work for other languages, including your Perl case above.

Here's a base document on Windows Shell's "Start" command:
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/start.mspx?mfr=true

I hope this is handy for anyone used to a *nix platform, launching
executables, and wanting to go cross-platform to Windows.

-Alex