LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-19-2005, 03:15 PM   #1
nooodles
LQ Newbie
 
Registered: May 2004
Location: Texas
Posts: 18

Rep: Reputation: 0
perl question


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.


any help would be appreciated. thanks!

Last edited by nooodles; 09-19-2005 at 03:21 PM.
 
Old 09-19-2005, 03:31 PM   #2
spooon
Senior Member
 
Registered: Aug 2005
Posts: 1,755

Rep: Reputation: 51
If you don't need the output except to have it printed, then you can just use system("<some command>")
 
Old 09-19-2005, 04:02 PM   #3
nooodles
LQ Newbie
 
Registered: May 2004
Location: Texas
Posts: 18

Original Poster
Rep: Reputation: 0
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
-----

any insight?
 
Old 09-19-2005, 09:43 PM   #4
puffinman
Member
 
Registered: Jan 2005
Location: Atlanta, GA
Distribution: Gentoo, Slackware
Posts: 217

Rep: Reputation: 31
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.
 
Old 09-20-2005, 02:11 AM   #5
cigarstub
Member
 
Registered: Sep 2005
Posts: 145

Rep: Reputation: 15
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.
 
Old 09-22-2005, 02:01 AM   #6
nooodles
LQ Newbie
 
Registered: May 2004
Location: Texas
Posts: 18

Original Poster
Rep: Reputation: 0
Hmm...yeah this stuff looks interesting. i would have to read this a couple times but i think this migh tsolve my problem.

Thanks! i'll post if i run into any snags
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl Question rjcrews Programming 15 12-12-2005 09:34 AM
Hiding code in PERL, perl gui question randomx Programming 1 06-26-2004 03:22 PM
Perl Question cbarone Linux - Software 1 12-17-2003 10:25 PM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 08:09 PM
Perl question oulevon Programming 12 05-31-2001 06:54 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration