http://qs321.pair.com?node_id=11113489


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.