control over shell script

Hi..
I have a perl program that uses "system" to execute a shell script called startengine. The script "startengine" itself calls a lot of other smaller scripts to setup the engine etc. It finally has to execute ./engine which is another shell script which is long and takes a long time to complete processing.

The "startengine" script looks like this

#!/bin/bash
echo In shell script............
/usr/agjy/bin/cleartool setview $1 <<END

cd /vobs/eng/work
. ./setup host-dbg gw

cd \$ENG_TARGET_ROOT/home/bin
pwd

/home/agjy/bin/stopAll
/home/agjy/bin/cleanup

./engine 2>&1 |tee $2

My problem is that the system call returns back to perl script without waiting for ./engine to finish processing..
I have tried sleep in the perl script which works only sometimes depending on machine speed. Another problem is that ./engine is a waiting process- ie if it runs correctly it should say "waiting for connection.. " and wait for input. the output of ./engine is written into the logfile ($2). The perl script then parses that
logfile looking for the "waiting for connection" string and proceeds to send input to the engine or shut it down depending on if string was matched or not.

I need something that will make sure ./engine is completely processed before control returns to perl script..
I hope i have made the problem clear and would really appreciate any help with this..

Thanks,
JLJ

use the Proc::Simple package to launch your shell script. Then you can keep watching the status of that launched process, know when it is finished, and also kill it if required.

Thank You Yogesh for replying.. I will try that but do you know of any other way without using packages?

The crude method is to modify the .engine script to write a line in the log "engine process completed" or something similar. Then in the Perl script, keep iterating in a loop to watch the log and when this line is found, continue further execution. But this is an unreliable method and should be avoided.

Use Perl's Thread model if you don't want to use external packages. This will help you: The Thread Model (Programming Perl) This is the 17th chapter of the Camel Book that I am referring.

But I recommend that you use the Proc::Simple package in this case, it will make your life simple.