ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a perl program that executes an external program/command using backticks. my problem is the program/command i execute sometimes issues an interrupt signal, which terminates my perl script. what i want my perl script to do is to be able to catch that signal (or ignore it) and continue on with the perl script.
E.g.
my $output=`<some command>`;
print $output;
*when i execute '<some command>' from the command line i get the error "User defined signal 2".
---
if <some command> sends an interupt signal, the perl script terminates w/out executing the next line. i want to be able to ignore the interrupt signal and proceed to the next line.
i actually need the output from the print command. depending on the state of the machine or the arguements i feed the command, it produces the 'User defined signal 2" conditionally.
i tried adding
$SIG{USR2} = 'INORE';
at the top of the script which it does execute the print command, but i get the error...
-----
rcvMsg1: Connection reset by peer
ms_init failed
-----
You can use the open function with the "-|" argument to read the output of a child process, see here. The standard modules IPC::Open2 or IPC::Open3 also allow lower level control to both the input and output of child processes.
Can you precise the program that terminates your script ?
I think that when your script calls a command, it passes the control to and run in the background. When the command terminates, it do not bring the script on. So you need to make your script able to control the behaviour of the command by making it to an environment like the terminal in which you run your script. Never let the command interact directly with the shell.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.