Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

doubts of a perl beginner in G_EVAL(perlEmbed)

by jithoosin (Scribe)
on Dec 26, 2005 at 07:52 UTC ( #519080=perlquestion: print w/replies, xml ) Need Help??

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

Hi monks
Let me explain my situation first.I am using a perl file written by another guy inside my C code.I am not supposed to edit the perl file which is written by my friend.The guy who wrote the perl file has used "exit(0)" inside it.I need to catch it.

So when i performed a super search i got a node Catching errors in embedded Perl and i also looked into using G_EVAL.The perldoc says it is possible to catch "die" inside the code and i tried it .It is working.Now my question is whether is it possible to catch the "exit(0)" statements in the perl code using G_EVAL. If it is not possible is there any other method to catch "exit(0)" in a perl code when it is called from C.Could any of the monks help me

  • Comment on doubts of a perl beginner in G_EVAL(perlEmbed)

Replies are listed 'Best First'.
Re: doubts of a perl beginner in G_EVAL(perlEmbed)
by McDarren (Abbot) on Dec 26, 2005 at 08:40 UTC
    hmm, from perldoc -f exit
    Don't use "exit" to abort a subroutine if there's any chance that someone might want to trap whatever error happened. Use "die" instead, which can be trapped by an "eval".

    That doesn't sound too promising....

    Do you actually need to catch the exit 0, or do you just need to know whether it terminated normally. AFAIK, a zero exit status generally means sucess, whereas anything else means that something went wrong. So perhaps you could just test the exit status of the Perl script, no?

      After reading the first reply i feel i must ask my friend to change the perl code ie exit(0) must be changed to "die".Thanks for the suggestion from the perl doc.
Re: doubts of a perl beginner in G_EVAL(perlEmbed)
by educated_foo (Vicar) on Dec 26, 2005 at 09:35 UTC
    Admittedly your friend's code is ill-mannered, but if it's UNIX, could you just use fork(2) and either wait(2) or waitpid(2), putting the G_EVAL in the child process? (I think StartProcess could be similarly applied on Windows, but have never tried.)

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://519080]
Approved by McDarren
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2023-01-31 09:37 GMT
Find Nodes?
    Voting Booth?

    No recent polls found