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

I urgently need some help!! I am trying to call a Perl script from another and capture the exit status (whether it was successful). How should I go about it? Please help.... Thanks in advance, Bucchi

Replies are listed 'Best First'.
Re: Call one Perl Script from another
by davorg (Chancellor) on Oct 24, 2006 at 07:45 UTC

    If you want to capture the return code from the other program then you need system.

    Other methods for calling external programs (and another Perl program is just like any other external program) include backticks (aka qx//), fork/exec and open.

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

Re: Call one Perl Script from another
by eyepopslikeamosquito (Archbishop) on Oct 24, 2006 at 08:34 UTC

    The return code is available in the 16-bit $? variable. For example:

    system('perl -e "exit 42"'); my $rc = $? >> 8; print "return code=$rc\n";
    For more details, see system et al, as suggested by davorg.

Re: Call one Perl Script from another
by planetscape (Chancellor) on Oct 24, 2006 at 15:36 UTC
Re: Call one Perl Script from another
by Smaug (Pilgrim) on Oct 24, 2006 at 08:59 UTC
      Hi Smaug, Thanks for the link. It is definitely good. Cheers, Bucchi
Re: Call one Perl Script from another
by blazar (Canon) on Oct 24, 2006 at 11:39 UTC
    I urgently need some help!!

    Well quite about everybody here is likely to, but saying so doesn't generally help. Well, at least you didn't include the remark in the Subject, which is terribly annoying and likely to be eventually counter-productive.

    I am trying to call a Perl script from another and capture the exit status (whether it was successful). How should I go about it? Please help....

    Does the answer change if the thing were not necessarily a Perl script, but a generic program? No! Thus I recommend you to read perldoc -f system, which seems the most viable solution, in absence of further info.

    Since the program to be called is a Perl script, there may actually be better strategies than plainly using system, but if you don't give further details, it's hard to say...

Re: Call one Perl Script from another
by Bucchi (Initiate) on Oct 24, 2006 at 08:48 UTC
    In order to invoke inc.pl , I wrote, system ("perl /u/niveditn/perl/myfolder/inc) ==0 or die "failed !" ; But it showed compilation errors like : Backslash found where operator expected at tmp line 1, near "rtf1\" Backslash found where operator expected at tmp line 1, near "ansi\" Backslash found where operator expected at tmp line 1, near "ansicpg1252\" Backslash found where operator expected at tmp line 1, near "deff0\" Backslash found where operator expected at tmp line 1, near "f0\" Backslash found where operator expected at tmp line 1, near "froman\" Backslash found where operator expected at tmp line 1, near "f1\" Backslash found where operator expected at tmp line 1, near "fswiss\" syntax error at tmp line 1, near "rtf1\" syntax error at tmp line 1, near "f1\" syntax error at tmp line 1, near "}}" Can you please help?

      That sounds very much like you're trying to execute an RTF file. Are you editing your code in Wordpad? You should make sure that you save the code as plain text. I recommend getting a real programmers editor like emacs or vi.

      --
      <http://dave.org.uk>

      "The first rule of Perl club is you do not talk about Perl club."
      -- Chip Salzenberg

        Hey !!! Thanks a ton!!! With notepad , I could finally call the other script!! Thanks again for helping , Cheers Bucchi