Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Determine if a program in a different terminal has ended

by renegadex (Beadle)
on Sep 17, 2009 at 10:46 UTC ( #795847=perlquestion: print w/ replies, xml ) Need Help??
renegadex has asked for the wisdom of the Perl Monks concerning the following question:

Hi! i have this code.
my $k = 0; while($k < 3){ system("gnome-terminal -e 'perl myscript.pl'"); }
This is what I want to happen.
Run the myscript.pl in a new terminal (it needs to run in a terminal for it to work properly... it has photorec batch commands inside)
The script should run again after it has finished running.

My problem is that since the script was ran on another terminal... I think the system command instantly finished when after executing the command since the program was launched in a new terminal... just like running a separate thread.
So what happens is that it runs the same script all at the same time instead of waiting for the first 1 to finish. Any help would be appreciated. :D

Or maybe, is there a way to run a perl script in a terminal like environment without the terminal?
Mabuhay Civil Engineers! :D

Comment on Determine if a program in a different terminal has ended
Download Code
Re: Determine if a program in a different terminal has ended
by almut (Canon) on Sep 17, 2009 at 11:15 UTC

    I just tried it (with gnome-terminal and xterm), putting a simple "sleep 2" in myscript.pl, and the terminals popped up sequentially, staying there for 2 seconds (which is what I would have expected, as you're not doing anything to explicitly run things in the background...).

    Could you elaborate on what exactly is happening in your case? Does the script actually execute? How do you run the commands within myscript.pl? Any errors?

    BTW, you probably meant to increment $k within your while loop... Or simply use for (1..3) {...}

      the myscript.pl takes a long time to finish and it also depends on the userinputs, it also has its own gui and other stuff. so everytime I run that script, it waits for user input such as button presses and other stuff... using a sleep() would be useless because the time that the script would finish is unknown. if there would be a way for the myscript.pl to send a signal or something that can be captured by the main script, maybe that might work? hehe but i don't know any...
      Mabuhay Civil Engineers! :D
        using a sleep() would be useless

        I just put the sleep in there for testing purposes, i.e. to emulate a script doing something that takes time... (if the script doesn't do anything, the terminal would of course also close immediately)

        I still wonder what's happening in your case.  The "normal" thing for a terminal would be to wait until the command it runs has finished...

        What happens on your system when you try

        for (1..3) { system("gnome-terminal -e 'sleep 2'"); }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://795847]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (15)
As of 2014-09-23 15:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (224 votes), past polls