in reply to Re: Semicolon behaviour in system call
in thread Semicolon behaviour in system call

Indeed... but what's the equivalent in a system call?

In any case, the testcase using 'echo' was simply to demonstrate the problem; it reproduces in any variety of ways, e.g.

cd C:\temp perl -e 'system("pwd; pwd");'

results in

pwd [-LP] [-d path]

in other words, a usage error... but *nix/MKS perl produces:

c:/temp c:/temp

I guess, in summary, what I'm asking is how a multi-command system call is made with standard Windows PERL distribs

Replies are listed 'Best First'.
Re^3: Semicolon behaviour in system call
by ikegami (Patriarch) on Mar 27, 2014 at 19:50 UTC

    Indeed... but what's the equivalent in a system call?

    system takes a shell command, so the equivalent of

    echo "1 & echo 2 & echo 3" & echo two dos & echo t

    using system is

    system('echo "1 & echo 2 & echo 3" & echo two dos & echo t');

    Do you realize you are launching a Windows build of Perl (ActivePerl or Strawberry Perl?), and that Windows build of Perl launch cmd rather than (non-existent) /bin/sh? In other words,

    system('pwd; pwd');
    is the same as
    system('cmd', '/x', '/c', 'pwd; pwd');

    Perhaps you are looking for

    # Adjust the path for your system system('c:\\progs\\cygwin\\bin\\sh', '-c', 'pwd; pwd');

      Thank you very much indeed for your analysis, and your code samples, and for the overall illumination provided

Re^3: Semicolon behaviour in system call
by kcott (Archbishop) on Mar 27, 2014 at 19:33 UTC

    Do you get the same output from

    C:\temp> pwd; pwd

    as you do from

    C:\temp> perl -e 'system("pwd; pwd");'

    Do the same check for:

    C:\temp> echo 1; echo 2; echo 3

    From Perl, you may need to put each command in an array and use "system $_ for @cmds", e.g.

    $ perl -e 'my @cmds = ("echo 1", "echo 2", "echo 3", "pwd", "pwd"); sy +stem $_ for @cmds' 1 2 3 /Users/ken/tmp /Users/ken/tmp

    [I don't have Perl running on any MSWin platform, so I can't test this for you.]

    -- Ken

      Hi Ken, thanks for that nice option, it doesn't quite work from the command line (issues identifying the closing "'"), but from a script it does the trick regardless of PERL distrib used

        Yes and no. ";" vs "&" is hardly the only difference between sh and cmd. Even the quotes are different.