Bigtwinz
Bigtwinz

Reputation: 61

Calling consecutive java tasks in a shell script

This may be a rudimentary question but the answer was not readily available.

I'd like to create a shell script that calls 3 tasks consecutively, but wait till the previous task is complete.

Like so:

a. call first Java program via ant b. call third party Java application c. call third Java program via ant

I'm wondering if there is a way to check and ensure a. is done before b. is called and same for b. and c.

thanks

Upvotes: 1

Views: 352

Answers (3)

Kai Sternad
Kai Sternad

Reputation: 22850

Assuming you are working in a *nix shell, an easy solution that comes to mind would be to just sequentially execute all three commands with the && operator:


#!/bin/sh
ant task -f build.xml && java org.mycompany.app && ant anothertask -f buld2.xml

The && operator makes

[...] each command execute in turn, provided that the previous command has given a return value of true (zero). At the first false (non-zero) return, the command chain terminates (the first command returning false is the last one to execute 1).

Upvotes: 0

lemotdit
lemotdit

Reputation: 448

java some.package

if [ $? -ne 0 ]; then exit -1; fi;

java some.other.package

By default calls inside the script are consecutive. If the first java execution 'some.package' doesn't return 0, the normal exit code, the script will exit with -1 without executing 'some.other.package'

Upvotes: 0

Michael Mrozek
Michael Mrozek

Reputation: 175705

By default ant tasks happen in the foreground, so your script won't continue until each ant task has finished. You only need to mess with things if you want the opposite behavior: all three tasks happening simultaneously

Upvotes: 1

Related Questions