By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,710 Members | 1,887 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,710 IT Pros & Developers. It's quick & easy.

quiting a program started by perl

P: 1
Hello Guys,

I wrote a script to run a file using a program installed on the system. Now, the whole thing works properly, except I have multiple files that I need the program to run on.
To do his I kept the whole thing in a loop, in which the variable of the loop corresponds to the name of the file.
So by thought, I expected perl to run the loop, open the file using that program and when it's done, it simply goes to the end of the loop and back to the begining and increments, then do it again. Eg.

Expand|Select|Wrap|Line Numbers
  1. for ($x=2; $x >= 0;$x--)
  2. {
  3. for ($y=2; $y >= 0;$y--)
  4. {
  5. system("prog name -f file_$x_$y.ext >tracker_$x$y.log");
  6. }
  7. }
but instead (and rather unexpected), it stops after the first loop, and then when I check its status, I notice the program has just stopped. It's finished what it has to do but it remains within that program, and perl just stays still (I'm guessing waiting for the program to exit).
Now, to solve this I always have to physically press cntrl - C [in the bash (terminal)], and this ends the program (not the script, but the program initiated by the script), and then the loop resumes, only to happen again.

That's why I was hoping I could make perl issue the 'cntrl-c; command and then the loop continues making the whole thing autonomous.
Now, if I make use of the kill, realised it would kill everything [(when I just want to kil the running program (not the script)]. I hope I was explanatory enough.

THanks in advance.
Jan 21 '09 #1
Share this Question
Share on Google+
2 Replies


Icecrack
Expert 100+
P: 174
if your running Linux, you could try to keep track of the programs PID and issue a Kill command in Linux with the pid for that program.
for e.g
Expand|Select|Wrap|Line Numbers
  1. system("kill pid");
  2.  
As for killing it another way i don't know, i have never tried to run another program from perl.
Jan 21 '09 #2

KevinADC
Expert 2.5K+
P: 4,059
He has this question on several perl forums where it has numerous replies. Including to use fork() and kill() amongst other recommendations.
Jan 21 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.