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

Hi Monks,
I have to execute another perl script and get the output of child script.
main.pl ... my $cmd=" perl C:\\ia\\getset_build_num.pl -mode get -p $outputname -t + $build_num_template -c $build_num_config"; my ($build_number,$message)= system($cmd);

The script C:\\ia\\getset_build_num.pl process a txt file and should return a value like
return "$bld_num";
problem here it is not returning the correct value.
please help me.

Replies are listed 'Best First'.
Re: return the output to the Parent script
by Corion (Patriarch) on Sep 22, 2008 at 07:44 UTC
      I tried backticks also. It gives the following message and returns nothing.
      Err:<code> Can't return outside a subroutine at ..<\code>

        This has nothing to do with backticks. As you're not showing any code that reproduces the problem, I can't help you further. Maybe consider posting self-contained code that exhibits the problem.

        That error message mostly happens if you have a program like the following:

        #!/usr/bin/perl -w use strict; return 'Hello';

        So you must be doing that somewhere in your code.

        If you want to pass data around in perl data structures, turn your script into a module, then you can ordinarily return data from it.
Re: return the output to the Parent script
by svenXY (Deacon) on Sep 22, 2008 at 08:03 UTC
    or even, as TIMTOWTDI, with open in its pipe form
    open($fh, '-|', 'some cmd to read from') or die '...'; while (<$fh>){ # read one line of output }
    Regards,
    svenXY
Re: return the output to the Parent script
by moritz (Cardinal) on Sep 22, 2008 at 07:43 UTC
    Read the documentation for system, it explains the return value. Which part isn't clear?

    Also system() will return only one value, so $message will always stay undef in your example.

Re: return the output to the Parent script
by Bloodnok (Vicar) on Sep 22, 2008 at 08:23 UTC
    One inquires as to how extensive your search for similar topics was - this topic, or something extremely similar, has had decent coverage of late.

    I'd be prepared to bet that it's been covered at length further in the past as well (tho', somewhat hypocritically, I haven't had a look ;-)...

    A user level that continues to overstate my experience :-))