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.


In reply to Re^2: External Program Arguments Problem by Anonymous Monk
in thread External Program Arguments Problem by jtroy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.