I once wrote a Perl script that was for managing the timing of starting
other scripts. By this I mean, it started a number of other programs
(also perl scripts) on a certain time schedule.
I found that the system() command in itself was not going to work
because th system() command waits for the program that it calls to
finish. This was no good because I needed to start multiple scripts
simutaneously and the waiting part was not going to work since each
script took quite a while to run.
Then I discovered the exec() command, which essentially does the same
thing as the system() command, but instead of waiting, it terminates
the current script after starting the script I called with it.
Now, I realize that some of you Perl gurus will probably have a better
answer than what I did, but at the time I didn't think of looking for
help online. What I ended up doing was using the two commands together
to get the desired result of my main script continuing as well as the
scripts I was calling, all running at the same time. I created a
simple script that had an exec() command in it that just pushed the
arguments given to it, into the exec() command. In my main script, I
used the system() function to call the script with the exec() script.
I'm starting a new paragraph here because that was getting busy.
Anyway, the reason this fixed my problem is that the system() function
called the exec() script and waits for it. The exec() script uses the
exec() function to call the program I want to run, and then the exec()
script terminates immediately. Then the main script continues because
the system() call is now finished waiting for the exec() script.
so, basically, here's how it looks, kinda.
- main script # give program and its args as args for execscrpt