Results 1 to 3 of 3
So I have this 3rd party program that can run commands on the server (command line in unix). The commands I want this 3rd party program to run on the ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 04-09-2008 #1
- Join Date
- Apr 2008
Help Running Programs In Sequential Order
The commands I want this 3rd party program to run on the server are to run 3 different programs
in order (order matters).
The first program takes a input file and then outputs a temp file.
Then the second program takes that temp file that program 1 created and uses that as input and produces another temp file. Finally the third program thats program 2's temp file output as input and outputs a final useful file.
The problem is that it will not wait for program 1 to finish before running program 2 so the file that it takes as input might not exist yet. How do I check or make it so that program 2 will not start until program 1 has finished? If I put these commands in a shell script and run the shell script, will it run the programs in order and wait for each program to finish before executing the next?
- 04-10-2008 #2
- Join Date
- Oct 2007
- Tucson AZ
In a bash script, separate the commands with a semi-colon.
- 04-12-2008 #3
- Join Date
- Nov 2007
- Córdoba (Spain)
For example, if foo is a normal program, if you run "foo" on command line, it will lock the shell until it ends the execution. So, anything after that command on the script, will not be run until this command ends.
But if you did "foo&", the program would be launched and automatically put into the background (it will continue running, but it will not lock the shell). So, the script will continue running the next command.
This is the normal behavior. But some programs fork themselves automatically, even if you don't put the trailing '&'.
In those cases (either if the program goes to background itself, or you use '&'), you might need to take another approach. For example, capture the PID of the process and then use the wait command:
#We launch glxgears on the background
#Capture its PID
#This waits until the program with the given PID ends
#Here we put more instructions, these will not be run until
#the wait command above unlocks the shell
echo "glxgears was closed, it's pid was $pid"