in reply to Re: External Program Arguments Problem
in thread External Program Arguments Problem
Okay, Google'd and tested out a few things. It turns out I can get it to work in cmd.exe by replacing " with "^"" (all four characters). This works both from the cmd.exe shell and calling it from Perl:
#### arg_test.pl #### my $output = `print_args.pl "Test" "Hi (12"^"" mix)" "test.txt" 2>&1`; print "$output";
C:\scripts>print_args.pl "Test" "Hi (12"^"" mix)" "test.txt" 2>&1 Arg 0 - Test Arg 1 - Hi (12" mix) Arg 2 - test.txt c:\scripts>arg_test.pl Arg 0 - Test Arg 1 - Hi (12" mix) Arg 2 - test.txt
However, this isn't consistent for other external programs. I wrote a simple C program to do the same thing as print_args.pl. Replacing " with "^"" in parameters still works from the command line, but now it fails when running it from Perl.
// PrintArgs.exe #include <stdio.h> int main(int argc, char **argv) { for (int i=0; i<argc; i++) { fprintf(stderr, "Arg %d: %s\n", i, argv[i]); } return 0; }
#### arg_test.pl #### my $output = `PrintArgs.exe "Test" "Hi (12"^"" mix)" "test.txt" 2>&1`; print "$output";
Here's the output I get running it directly in the shell and then from Perl:
C:\scripts\arg_problem>PrintArgs.exe "Test" "Hi (12"^"" mix)" "test.txt" 2>&1 Arg 0: PrintArgs.exe Arg 1: Test Arg 2: Hi (12" mix) Arg 3: test.txt C:\scripts\arg_problem>perl_test.pl Arg 0: PrintArgs.exe Arg 1: Test Arg 2: Hi (12^ Arg 3: mix) test.txt 2>&1
This is killing me. How is the Perl-shell interaction fine in the first case but not the second? Is Perl using the exact shell on my system (c:/windows/system32/cmd.exe) or its own version? Could it be processing the parameters in some way before passing them off to the shell?
I'd really appreciate any ideas on what's going on.
|
|---|