in reply to System call doesn't recognise '>'

system LIST doesn't use the shell. > is a shell command. If you wanted to use execute a shell command using system, you'd have to do
system('sh', '-c', 'foo > file');

or the equialent

system('foo > file');

The latter is also suitable for Windows.

Replies are listed 'Best First'.
Re^2: System call doesn't recognise '>'
by Lauras (Initiate) on Dec 10, 2008 at 21:52 UTC
    my @array = ($command, $arg1, $arg2, $arg3); system ('@array > $outfile');

    Results in:

    Can't spawn "cmd.exe": No such file or directory at D:\advanced_programming\test_syscall.pl line 11.

      system ('@array > $outfile');

      That line doesn't do what you think it does. Single quotes don't interpolate. You want to use double quotes and you want to check the return code of system():

      system( "@array > $outfile" ) == 0 or die "Couldn't launch [@array > $outfile]: $!/$?";
        my @array = ($command, $arg1, $arg2, $arg3); system( "@array > $outfile" ) == 0 or die "Couldn't launch [@array > $outfile]: $!/$?";

        Results in:

        Can't spawn "cmd.exe": No such file or directory at D:\advanced_progra +mming\test_syscall.pl line 29. Couldn't launch [C:\clover\clover.exe D:\advanced_programming\vb_van_m +otif.dat D:\advanced_programming\test.fa D:\advanced_programming\back +ground.fa > C:\clover\out.txt]: No such file or directory/65280 at D: +\advanced_programming\test_syscall.pl line 29.

        Again: If I paste the string C:\clover\clover.exe D:\advanced_programming\vb_van_motif.dat D:\advanced_programming\test.fa D:\advanced_programming\background.fa > C:\clover\out.txt in command line cmd.exe , it returns perfect output to the out.txt file.

      I'd be surprised if there was a file named @array...