in reply to Re^5: System call doesn't recognise '>'
in thread System call doesn't recognise '>'

For this code:
my @array = ($command, $arg1, $arg2, $arg3); system (@array);

It runs perfectly and returns the output to StandardOUT

Clover: Cis-eLement OVERrepresentation Compiled on Jul 18 2006 Getting raw scores... Reading background sequences... Analyzing background sequences... Getting motif locations... Sequence file: D:\advanced_programming\test.fa (3 sequences, 16050 bp, + 55.6% C+G) Motif file: D:\advanced_programming\motif.dat (2 motifs) *** Over- and Under-represented Motifs: Motif Raw score P-value from randomizing background *** Motif Instances with Score >= 6: Motif Location Strand Sequence Score Background sequence files: D:\advanced_programming\background.fa (2 sequences, 284279 bp, 37.3% + C+G) Randomizations: 1000 P-value threshold: 0.01 Motif score threshold: 6 Randomize nucleotides OFF Randomize dinucleotides OFF Randomize motifs OFF Lowercase filtering OFF Pseudocount: 0.375 Random seed: 1

This on the other hand:

my @array = ($command, "$arg1 $arg2 $arg3"); system (@array);

Returns:

Clover: Cis-eLement OVERrepresentation Compiled on Jul 18 2006 Error: motif and sequence files required Usage summary: clover [options] mymotifs myseqs.fa [BGfiles]

Replies are listed 'Best First'.
Re^7: System call doesn't recognise '>'
by cdarke (Prior) on Dec 10, 2008 at 16:08 UTC
    Use this:
    my $status = system ("$command $arg1 $arg2 $arg3 > $outfile"); if ($status) { print STDERR "Error: ", $status >> 8, "\n"; }
      That results in:

      Can't spawn "cmd.exe": No such file or directory at D:\advanced_progra +mming\test_syscall.pl line 13. Error: 255
Re^7: System call doesn't recognise '>'
by Bloodnok (Vicar) on Dec 10, 2008 at 16:21 UTC
    Ahh, methinx the mists begin to clear a little more (& not before time, I hear you say;-) ... '>' is an argument to the shell, not $command, thus if you need the output redirected in the manner you require, you'll have to use system "@array > $outfile" form - assuming @array contains $command.

    Alternatively you could use perl to perform the redirection by using open e.g.

    open CMD, "@array > $outfile" or die "open() failed - $!";
    In both cases, auto-stringifying the array.

    A user level that continues to overstate my experience :-))

      my @array = ($command, $arg1, $arg2, $arg3); system "@array > $outfile";

      Results in:

      Can't spawn "cmd.exe": No such file or directory at D:\advanced_progra +mming\test_syscall.pl line 11. and my @array = ($command, $arg1, $arg2, $arg3); open CMD, "@array > $outfile" or die "open() failed - $!";

      gave:

      Name "main::CMD" used only once: possible typo at D:\advanced_programm +ing\test_syscall.pl line 17. open() failed - Invalid argument at D:\advanced_programming\test_sysca +ll.pl line 17.
Re^7: System call doesn't recognise '>'
by Corion (Patriarch) on Dec 10, 2008 at 16:18 UTC

    This code is not what was suggested:

    my @array = ($command, "$arg1 $arg2 $arg3"); system (@array);

    What was suggested to you was:

    my @array = ($command, "$arg1 $arg2 $arg3"); system("@array"); # or, more verbose: my $cmd = join " ", @array; system ($cmd) == 0 or die "Couldn't launch [$cmd]: $!/$?";
      Both ways you describe work perfectly, but do not redirect the output.