quiting a program started by perl

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Vergil
    New Member
    • Aug 2007
    • 1

    quiting a program started by perl

    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.

    Code:
    for ($x=2; $x >= 0;$x--)
    {
    for ($y=2; $y >= 0;$y--)
    {
    system("prog name -f file_$x_$y.ext >tracker_$x$y.log");
    }
    }
    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.
    Last edited by eWish; Jan 21 '09, 01:06 AM. Reason: Please use the code tags
  • Icecrack
    Recognized Expert New Member
    • Sep 2008
    • 174

    #2
    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
    Code:
    system("kill pid");
    As for killing it another way i don't know, i have never tried to run another program from perl.

    Comment

    • KevinADC
      Recognized Expert Specialist
      • Jan 2007
      • 4092

      #3
      He has this question on several perl forums where it has numerous replies. Including to use fork() and kill() amongst other recommendations .

      Comment

      Working...