in reply to Parsing Windows CommandLine from Perl
Fired up ye olde VM, and found the solution. You see, you can write a batch script that does the parsing for you... it looks like this:
@ECHO OFF SetLocal EnableDelayedExpansion set ARGS= :parse_args if not %1.==. ( set ARG=%1 set ARGS=!ARGS! ^"!ARG:"=\"!^" shift goto :parse_args ) call perl getargs.pl %ARGS%
I rewrote the perscript to fit the output of your C code, but it is basically the same:
unshift(@ARGV,$0); for my $n (0..$#ARGV) { print "$n:$ARGV[$n]:\n" }
The resulting output is then:
C:\>parseargs.bat "abc "" def" bob 0:getargs.pl: 1:"abc "" def": 2:bob:
Which is not exactly the same what you wanted, but it is actually exactly what you typed in as arguments. Now, it is time to s/""/"/g and you are ready to go. What I mean is:
unshift(@ARGV,$0); @ARGV = map {s/^"(.*)"$/$1/ ? s/""/"/g && $_ : $_ } @ARGV; for my $n (0..$#ARGV) { print "$n:$ARGV[$n]:\n" }
Dont ask why I used map... I am not sober at the moment...
0:getargs.pl: 1:abc " def: 2:bob:
note to self: do not forget bob
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Parsing Windows CommandLine from Perl
by fishmonger (Chaplain) on Apr 17, 2015 at 20:30 UTC | |
|
Re^2: Parsing Windows CommandLine from Perl
by Anonymous Monk on Apr 17, 2015 at 20:53 UTC |