Adam_G
Adam_G

Reputation: 7879

Running multiple octave scripts from command line

I have multiple octave scripts, that I need to execute in order. The 2nd script is dependent upon the first script, so it must wait for the first script to complete. I'd also like to pass in 2 arguments from the command line. The following script, though, does not wait for the first script before executing the second. How can I correct this?

EXP_ID = $1;    
NUM_FEATURES = $2;

cd fisher;
octave computeFisherScore-AG.m $EXP_ID;
cd ..;
octave predictability-AG.m $EXP_ID $NUM_FEATURES;

Upvotes: 0

Views: 2150

Answers (2)

konsolebox
konsolebox

Reputation: 75478

Perhaps your octave script runs in a background. You can use this workaround:

waitpid() {
    while kill -s 0 "$1" >/dev/null 2>&1; do
        sleep 1
    done
}

cd fisher;
octave computeFisherScore-AG.m $EXP_ID;
waitpid "$!"
cd ..;
octave predictability-AG.m $EXP_ID $NUM_FEATURES;

May I also suggest that you quote your arguments properly to prevent unexpected word splitting and pathname expansion:

cd fisher
octave computeFisherScore-AG.m "$EXP_ID"
waitpid "$!"
cd ..
octave predictability-AG.m $EXP_ID "$NUM_FEATURES"

Semicolons may also not be necessary.

Upvotes: 1

Tripp Kinetics
Tripp Kinetics

Reputation: 5439

Try:

EXP_ID = $1;    
NUM_FEATURES = $2;

cd fisher;
octave computeFisherScore-AG.m $EXP_ID;
wait
cd ..;
octave predictability-AG.m $EXP_ID $NUM_FEATURES;
wait

Check out http://www.lehman.cuny.edu/cgi-bin/man-cgi?wait+3

Upvotes: 1

Related Questions