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:
Running the script, I get the following error: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";
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.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 '
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.
Back to
Seekers of Perl Wisdom