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

my @array = qq/$command $arg1 $arg2 $arg3 > $outfile/; system "@array";

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

On the other hand:

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

system (@array);

Results in:

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^5: System call doesn't recognise '>'
by Bloodnok (Vicar) on Dec 10, 2008 at 15:05 UTC
    Does the command work without redirection when run by system?

    A user level that continues to overstate my experience :-))
      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]
        Use this:
        my $status = system ("$command $arg1 $arg2 $arg3 > $outfile"); if ($status) { print STDERR "Error: ", $status >> 8, "\n"; }
        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 :-))

        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]: $!/$?";