in reply to Semicolon behaviour in system call

Windoze (Win7 in the example below) echo consumes everything on the command line unless it's quoted. Try:

c:\@Work\Perl\monks>echo "1 & echo 2 & echo 3" & echo two dos & echo t +hree "1 & echo 2 & echo 3" two dos three

MKS is intended to emulate *nix and is probably running in its *nix-ish shell, hence the *nix-ish behavior.

Update: Fixed command-line example code: && vice &.

Replies are listed 'Best First'.
Re^2: Semicolon behaviour in system call
by casual_prgmr (Initiate) on Mar 27, 2014 at 19:02 UTC

    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

      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

      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