in reply to system command has problem with '>>'

Its because you didnt read the documentation clearly. The ls program doesn't know what to do with >> or 2>&1, its not sh/csh/perl -V:sh

Use systemx from IPC::System::Simple

use IPC::System::Simple qw[ systemx ]; ...

Replies are listed 'Best First'.
Re^2: system command has problem with '>>'
by mnooning (Beadle) on Mar 30, 2010 at 00:26 UTC
    Not true. The shell processes '>>', not 'ls', as can be seen from the pastes below.
    Anyone else have any ideas on this?

    $ rm aa
    $ ls example_file.txt >> aa
    $ cat aa
    example_file.txt
    $ ls exam*
    example_file.txt
    $ ls example_file.txt >> aa
    $ cat aa
    example_file.txt
    example_file.txt
      Not true. The shell processes '>>', not 'ls', as can be seen from the pastes below.

      Thats what I said.

      Anyone else have any ideas on this?

      Like I said, use IPC::System::Simple systemx, it process >> like the shell without invoking the shell, or like JavaFan said, invoke the shell

        it process >> like the shell without invoking the shell

        No.

        $ dir foo ls: foo: No such file or directory $ perl -MIPC::System::Simple=systemx -e'systemx "ls", ">>", "foo"' ls: >>: No such file or directory ls: foo: No such file or directory "ls" unexpectedly returned exit value 2 at -e line 1 $ perl -MIPC::System::Simple=systemx -e'systemx "ls >> foo"' "ls >> foo" failed to start: "No such file or directory" at -e line 1 $ dir foo ls: foo: No such file or directory

        Same goes for 2>&1

        $ perl -MIPC::System::Simple=systemx -e'systemx "ls 2>&1"' "ls 2>&1" failed to start: "No such file or directory" at -e line 1 $ perl -MIPC::System::Simple=systemx -e'systemx "ls", "2>&1"' ls: 2>&1: No such file or directory "ls" unexpectedly returned exit value 2 at -e line 1

        It would defy the entire point of systemx if any argument was treated specially.