LanX has asked for the wisdom of the Perl Monks concerning the following question:
I need to write a Perl script which is generating a .bat-file while passing it's command line arguments 1-to-1
Is there any way to access the "raw" command-line in order to catch quoting and escaping?
To highlight the problem:
D:\>perl -E"say qq(@ARGV)" "1 2" "3" 4 1 2 3 4
As you can see are all quotes and escapes lost while calling Perl (for good reasons)
But my script has to generate another .bat which does
... some_cmd "1 2" "3" 4 ...
Typical edge-case justifying this problem are win-paths with whitespace, but cmd.exe has also some arcane escaping rules.
I already have a workaround:
I discovered that .bat has %* to hold the verbatim command line arguments, and came up with a workaround of a .bat calling my perl-script
D:\tmp\exp>type cmd_wrapper.bat @echo off echo %* |perl -wE"chomp(my $args = <STDIN>);say qq(some_cmd $args)" D:\tmp\exp>cmd_wrapper.bat "1 2" "3" 4 some_cmd "1 2" "3" 4 D:\tmp\exp>
Question: any better solution?
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
PS: I don't think this question is overly Win specific, when creating a bash script on Linux I'd face the same problem.
|
|---|