Quoth
(PilotMI80):
> Finally I managed to do what I wished :
> my $ProgramExe = "\"C:\\The path to the\\executable.exe\"";
> my $OneArgument = "OneArgumentThatDoesNotContainSpace";
> my $SecondArgument = "\"D:\\Another Argt\\that contains spaces\"";
>
> system("start \"\"", $ProgramExe, $OneArgument, $SecondArgument);
You don't need any of this mess. Perl on Win32 knows how to quote
arguments correctly for the standard command-line parsing routines:
my $ProgramExe = 'C:\\The path to the\\executable.exe';
my $OneArgument = 'OneArgument';
my $SecondArgument = 'D:\\Another argt';
system 'start', $ProgramExe, $OneArgument, $SecondArgument;
> Some explanations for the ones who may encounter this concern (and
> feel free to correct me if I am wrong or not precise enough) :
> - system behaves differently whether it is passed a scalar argument or
> a list. I will not repeat the FAQ but it is often useful to force LIST
> context to avoid misinterpretation by the shell. (So we meet the form
> exec {"FakeName"} @ForcedToBeListCommandLine)
Perl will not call the shell for a one-arg system or exec unless the arg
contains shell metachars.
You have got the indirect object and the first arg the wrong way round:
the indirect object is what is actually being executed. In any case,
they should be the same (unless you need them different), so to run a
command with no args but with spaces in the name use
my $cmd = '/path to/command';
system {$cmd} $cmd;
> - I use "start" because I'm running on Win32, so it let the system
> launch a program as if it was launched from the start menu/Run.
> Otherwise, the script waits for the command to end (exec does not work
> neither cause it just turns the script process to the one just
> launched and there is no point of return)
Yup. You could also use Win32:

rocess, if you wanted more control over
your 'child'.
> - \"\" is the FakeName, the name we invoked the program under. (In
> this case I don't need to pretend my program was launched under a
> particular name so I let it blank)
No. I am actually rather surprised this worked at all...
You have *not* used the indirect object syntax here. Those ""
are inside the first arg, so what you are asking Perl to do is execute a
program called (literally)
start "".exe
(or some other executable extension). The fact that the windows
doesn't use the C arg-passing convention means that it worked out what
you meant anyway...
> - $ProgramExe and $SecondArgument were quoted in order to have the
> white spaces preserved on the command line issued;
Nope. Perl will deal with this for you if you use system LIST.
> - I kept my different arguments in a LIST (and thus separated) not to
> have to rebuild my command line for any argument I want to issue but
> they could have been grouped together into one argument.
Nope. system LIST is quite different from system SCALAR, as you said to
start with.
Ben
--
If you put all the prophets, | You'd have so much more reason
Mystics and saints | Than ever was born
In one room together, | Out of all of the conflicts of time.
The Levellers, 'Believers'