Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Close script with open system call

by Eily (Monsignor)
on Feb 27, 2020 at 13:39 UTC ( [id://11113489]=note: print w/replies, xml ) Need Help??


in reply to Close script with open system call

If the issue is that you only want one process to be executing at the end of your script, or you want the end of script clean-up to be triggered exec should do fine.

If you want to get back control in the console, then neither system nor exec will do what you want, as in the first case the process you started by calling the script will wait for the editor to close, and in the second the process will turn into the editor's, so by definition won't have stopped until the editor has stopped.

On linux fork can be used like this:

fork and exit; exec($command)
Which will do what you want (a new process will be created, but the parent won't wait for it before exiting). On Windows I don't know... (it might work with the correct build of perl, it doesn't with my strawberry perl 5.30). You might want to redirect the editor's output as well, if you don't want messages to pop up in your console.

Edit: a simple test to demonstrate (using linux quotes since fork isn't implemented in my Windows perl)

perl -E 'fork and exit; exec q<perl -E "sleep 10; say 1">'
You then have 10 seconds to try and execute other commands before the 1 is displayed.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11113489]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-19 19:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found