http://www.perlmonks.org?node_id=967137


in reply to Trapping diagnostic messages

If my Google searches results are correct, the "SAM header is present" line comes out on STDOUT. The backticks will capture STDOUT by default but with some redirection, we can make it only capture STDERR where real errors should show up. See http://perldoc.perl.org/perlop.html#`STRING` for more details.

# discard STDOUT but capture STDERR in @out my @out = `/home/applications/samtools-0.1.7a/samtools view -bS $ARGV[ +0] 2>&1 1>/dev/null`; print OUT @out;

If you really do want the "SAM header is present" line to come out on STDOUT then you could do something like this.

# redirect STDOUT to stdout.log and capture STDERR in @out my @out = `/home/applications/samtools-0.1.7a/samtools view -bS $ARGV[ +0] 2>&1 1>stdout.log`; print OUT @out; my $stdout = do { local( @ARGV, $/ ) = 'stdout.log'; <> }; # slurp the + contents of stdout.log into $stdout print $stdout;

Replies are listed 'Best First'.
Re^2: Trapping diagnostic messages
by Eldan Aranye (Acolyte) on Apr 26, 2012 at 00:53 UTC
    Thank you for your reply! Actually, I tried adding 2>&1 to the command yesterday and it worked. It captured the STDOUT, thus preventing Galaxy from interpreting it as an error. Thanks again!