in reply to Quote marks lost in system() calls

Recall that system() behaves differently with one argument than it does with multiple. Perl treats a single argument as though it were a shell command, scanning for and processing shell metacharacters. Having played with it a bit, I'm not 100% convinced that on NT it behaves as one would expect it to coming from Unix.

Does

system("at", "12:00", "program.exe", '"the.server.org:1234"');
work any better for you?

Replies are listed 'Best First'.
Re: Re: Quote marks lost in system() calls
by dws (Chancellor) on Dec 21, 2000 at 04:45 UTC
    I tried the following on NT 4.0 with ActiveState 5.005_03.
    if ( @ARGV ) {
        foreach my $i ( 0 .. $#ARGV ) {
            print "ARVG[$i]: ", $ARGV[$i], "\n";
        }
        exit(0);
    }
    system("perl $0 foo bar");
    system('perl ' . $0 . ' "foo bar"');
    system("perl $0 foo \"bar baz\"");
    system("perl $0 foo \"\"bar baz\"\"");
    system("perl", $0, "foo", '"bar baz"');
    
    which yielded
    ARVG[0]: foo
    ARVG[1]: bar
    ARVG[0]: foo bar
    ARVG[0]: foo
    ARVG[1]: bar baz
    ARVG[0]: foo
    ARVG[1]: bar
    ARVG[2]: baz
    ARVG[0]: foo
    ARVG[1]: bar baz
    
    Unless I missed something, this suggests that you may be SOL on getting the doublequotes passed through on NT.
      This seems to behave as you desire, though I'm still not sure if its what Three-G wants (from his description, I thought its what I previously posted):
      if ( @ARGV ) { foreach my $i ( 0 .. $#ARGV ) { print "ARVG[$i]: ", $ARGV[$i], "\n"; } exit(0); } system("perl", $0, 'foo', '"\"bar baz\""'); # or this: system("perl", $0, 'foo', qq("\\"bar baz\\"")); ARVG[0]: foo ARVG[1]: "bar baz"
        Ha! Good catch. ++ for runrig.