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

italdesign has asked for the wisdom of the Perl Monks concerning the following question:

Hello again monks. Please tell me what I'm doing wrong. Here's a piece of code to illustrate what I'm trying to do:
use strict; use warnings; my $cmd = qq{ /usr/bin/wget "http://www.google.com" }; $cmd .= q{ |& tee /path/to/tee.log }; my $result = `$cmd`; print "$result\n";
Running the script, I get the following error:
sh: -c: line 0: syntax error near unexpected token `&' sh: -c: line 0: `/usr/bin/wget "http://www.google.com" |& tee /path/t +o/tee.log '
Yet, if I copy and paste the EXACT command reported in the error msg (namely /usr/bin/wget "http://www.google.com"  |& tee /path/to/tee.log) and run it on the command line, it works just fine.

I've tried several variations of this, including using system() and exec() instead of ``, as well as escaping | and &. Nothing works.

I am running csh if that makes any difference.

Ultimately what I'm trying to do is run wget and have the output (STDERR + STDOUT) sent to both 1) a log file, as well as 2) a variable in my program. I've looked at Capture::Tiny but it seems to only accomplish one or the other.