On Windows, the following C program:
when run like this:#include <stdio.h> int main(int argc, char* argv[]) { int i; for (i = 0; i < argc; ++i) { printf("%d:%s:\n", i, argv[i]); } return 0; }
prints:> arg.exe "abc "" xyz"
Though escaping double quotes inside a double quoted string by repeating them (as above) is ungainly, it is common in the Windows world and I need to support it.0:arg.exe: 1:abc " xyz:
Notice that the following Perl program:
when run with the same command line arguments:for my $arg (@ARGV) { print "$arg:\n" }
prints instead:> perl arg.pl "abc "" xyz"
abc ": xyz:
I tried:
to get at the Windows command line, but ran into the "random crashing problem" described at Win32::API Memory Exception with GetCommandLine() (which returns a static string).use strict; use warnings; use Win32::API; my $getcmdline = Win32::API->new( 'kernel32.dll', 'GetCommandLine', [] +, 'P' ) or die "error: Win32::API GetCommandLine: $^E"; my $cmdline = pack 'Z*', $getcmdline->Call(); $cmdline =~ tr/\0//d; # remove any NULLs left over from pack Z* $cmdline =~ s/\s+$//; # remove trailing white space print "cmdline=$cmdline:\n";
It seems I'll need to use Win32::CommandLine (which I cannot currently get to build cleanly) or write a C front end to do the argument passing before launching Perl. Is there another way around this that I've missed?
In reply to Parsing Windows CommandLine from Perl by eyepopslikeamosquito
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |