#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    6
    Rep Power
    0

    Call external command check for core dumped


    Hello all,

    I have to debug someone's code and I don't know much about Perl. I tried to google but found no solution. I am puzzled that I found no similar problem online. I am stuck at trying to display an error message or copy a file when there is a core dumped calling external program. This is the code:

    open CMD, "$cmd 2>&1 |"
    or die `cp $StdInFile /tmp`;

    or

    open CMD, "$cmd 2>&1 |"
    or die "cmd failed: $cmd";

    The program exists and working. However, the program fails whenever user enters bad inputs and it core dump. When core dump it never executes die. Why? How can I get it to execute die when there is a core dump? Am I missing something here?

    Thanks
    btran
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    776
    Rep Power
    495
    Hmm, not sure I will be able to help very much. First, the syntax used in your commands is unknown to me and looks pretty strange to me.

    Second, if you get a core dump, it means that your system crashed (well, almost crashed, it was able to recover, but only by killing the faulty process -- my explanation is probably not very accurate technically, but that's the idea.). In other words, it is not a Perl error, but a Unix error when running the command issued by the Perl script. Perl cannot control that.

    The die function will enable you to report an error internal to your program (e.g. @_ contains only two items, and the subroutine exprects three), a system call error (the system call was not able to open the file or the socket) or even a system command (with the backticks or the system function) if it returns a failure status (it was impossible to create the directory called for in the `mkdir $foo`, perhaps because it already existed or because you had unsufficient privileges), but it cannot catch a system command running amok to the point that the OS had to kill it in emergency to avoid losing control, which is what is usually happening when Unix creates a code dump (perhaps the command is exhausting the full system memory).
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,875
    Rep Power
    1225
    You should be able to trap the core dump if you use IPC::System::Simple to run your command instead of using open.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    6
    Rep Power
    0
    Thank you for clearing that up. I thought that was the case.

    Thanks
    btran

    Originally Posted by Laurent_R
    Hmm, not sure I will be able to help very much. First, the syntax used in your commands is unknown to me and looks pretty strange to me.

    Second, if you get a core dump, it means that your system crashed (well, almost crashed, it was able to recover, but only by killing the faulty process -- my explanation is probably not very accurate technically, but that's the idea.). In other words, it is not a Perl error, but a Unix error when running the command issued by the Perl script. Perl cannot control that.

    The die function will enable you to report an error internal to your program (e.g. @_ contains only two items, and the subroutine exprects three), a system call error (the system call was not able to open the file or the socket) or even a system command (with the backticks or the system function) if it returns a failure status (it was impossible to create the directory called for in the `mkdir $foo`, perhaps because it already existed or because you had unsufficient privileges), but it cannot catch a system command running amok to the point that the OS had to kill it in emergency to avoid losing control, which is what is usually happening when Unix creates a code dump (perhaps the command is exhausting the full system memory).
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    6
    Rep Power
    0
    Thank you for your suggestion. I will try that.

    Thanks
    btran

    Originally Posted by FishMonger
    You should be able to trap the core dump if you use IPC::System::Simple to run your command instead of using open.

IMN logo majestic logo threadwatch logo seochat tools logo