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

Hi monks,

I used "system" command to run shell script through my perl script.These shell script is to start or stop weblogic servers. In one of the scenario,i stopped the server manually,i ran my perl script which again ran shell script using system command to stop the server. After executing that line(stop server),the script got terminated instead of executing the next left out lines.I am confused what's making it get terminated ?

example:program terminates after executing system call

#!/usr/bin/perl system("./server_down.sh"); #script terminates here, why ???? #below lines will not execute print "line 1"; print "line 2";

Replies are listed 'Best First'.
Re: After system call, scripts is getting terminated
by roboticus (Chancellor) on Jan 08, 2014 at 12:20 UTC

    nithins:

    If the server down script has some noisy output and spawns other noisy processes, your print statement output might be buried in the middle of the command output.. Try putting a long sleep after the system statement, and add "\n" on your print statements, and see if you can see your output.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re: After system call, scripts is getting terminated
by hippo (Archbishop) on Jan 08, 2014 at 14:26 UTC

    Here's a counter example for you:

    #!/usr/bin/perl system("echo foo"); print "line 1"; print "line 2";

    You'll notice that this script does not terminate after the system call. So, the difference is whatever your shell script is doing. (Note: I've preserved your lack of newlines in the print statements, perhaps you are looking for 2 lines of output where there is in fact only one?)

Re: After system call, scripts is getting terminated
by LanX (Saint) on Jan 08, 2014 at 11:44 UTC
    Maybe you should read "How do I post a question effectively?" again? :)

    First and foremost, think through your question.
    • Can you explain it clearly to yourself?
    • Can you explain it to others?
    • What example data would help them understand the issue?
    • What's not happening that you think should happen, or happening that you think should not (or don't understand)?
    ...

    Show us that you've made an effort.
    • Show your code (at least the problematic snippet)
    • Explain in detail what you get (include sample output, error messages and warnings, for example).
    • Tell us how your output means your script isn't working.

    If you do, it's likely someone will provide pointers in the right direction.

    You already read it, right? ;-)

    So what do you think might help us to help you?

    Cheers Rolf

    ( addicted to the Perl Programming Language)

    update

    Thanks for providing a code example now! =)

    Please mark updates in the future.

Re: After system call, scripts is getting terminated
by Anonymous Monk on Jan 08, 2014 at 12:12 UTC
Re: After system call, scripts is getting terminated
by marinersk (Priest) on Jan 08, 2014 at 18:12 UTC
    Make these changes and see if it provides any clues:
    #!/usr/bin/perl print "Attempting shutdown script\n"; my $sysret = system("./server_down.sh"); print "-----[ Results ]---------------\n"; print "$sysret\n"; print "-----[ End of Results ]--------\n"; #script terminates here, why ???? #below lines will not execute print "line 1"; print "line 2";

    If nothing prints after "Attempting ...", then you have a problem with the shell script (or at least your efforts to invoke it).

Re: After system call, scripts is getting terminated
by Anonymous Monk on Jan 08, 2014 at 11:39 UTC

    ...

    on line 42 you have a termination command that ends the script

Re: After system call, scripts is getting terminated
by oiskuu (Hermit) on Jan 08, 2014 at 21:22 UTC

    This server_down script is using kill? Consider this:

    system("kill 1 0"); print "line 1"; print "line 2";
    Fix the server_down.sh, or ignore signals in your perl script. (See perlipc.)