Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clarification of system,exec,fork

Status
Not open for further replies.
Jun 3, 2007
84
US
Hello all I am trying to wrap my head around what the best way to call another perl script from within perl script is.

exec was my first choice as I just want to call/run the second script (call it and let is run in the BG) and not have my current script wait for the script to finish before moving. I am not checking for output of the script or any of that, just need to call it.

What would be the best way to accomplish this?

Thing that I noticed when running exec is that it exits once the exec command is called, so my script just finished prematurely.

With system the script waits until the called script is done running which is what I don't want.

If someone could point me in the right direction I would really appreciate it.

THANKS!!
 
I cheat and call it using backticks, throwing away the value;

my $dummy = `ls -l`;

 
exec effectively replaces the currently running executable with the new one, rather than "calling" it.

system (as you know) calls the new executable and returns control to the caller when it completes. I would expect backticks to do the same, so I'm not sure why that worked better for you?

fork is probably the one that you want, it effectively clones the currently running process into two, one the child of the other, but you can determine by the returned value whether you are now running in the "parent" or "child" process, and take different action in each (i.e. perform parallel work in the child while the parent continues with its work).

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top