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

Hi,
I am trying to capture the output of a make call using the system command
system("system("$MAKECOMMAND | tee -a ./prepare_$target.log");
while $MAKECOMMAND is the call for the makefile.

but I get the error messsage -

sh: -c: line 1: syntax error near unexpected token `|' sh: -c: line 1: `| tee -a ./prepare_lint.log'
do you have any idea how can the user will see the output in the stdout and laso in a log file ?

Please advice
Simona

jdporter added code tags

Replies are listed 'Best First'.
Re: system call for makefile
by Fletch (Bishop) on Jan 25, 2006 at 12:08 UTC

    Without showing what exactly's in $MAKECOMMAND people are only going to be guessing, but your problems in your command that's getting passed to the shell not your perl. You may have a trailing semicolon, or another | on the end of it, or who knows what.

    Another aid in debugging is to build what you're passing to system in a scalar and print that scalar's contents out so you know exactly what you're giving to the shell.

    my $cmd = "$MAKECOMMAND | tee ..."; print STDERR "cmd: !!$cmd!!\n" if $DEBUGGING; my $ret = system( $cmd );
Re: system call for makefile
by helphand (Pilgrim) on Jan 26, 2006 at 04:27 UTC

    Works fine here, but the line of code you show above is bad. Should be...

    use strict; use warnings; my $MAKECOMMAND='make'; my $target='test'; system("$MAKECOMMAND | tee -a ./prepare_$target.log");

    When run in a directory with a valid Makefile, it worked perfectly for me and the log contained the stdout messages.

    Scott