wait for batch script to finish ran from java process

Running batch scripts through java and wait for it to complete which internally calls java processes.
The below example show how can we wait for the script to complete running.


public static void main(String[] args) throws InterruptedException,
            IOException {
        System.out.println("Starting ");
Runtime runtime = Runtime.getRuntime();
            String[] command = { "cmd.exe", "/C", "start /WAIT",
                    "C:\\Users\\IBM_ADMIN\\Desktop\\BVT31\\BVT31\\xFAST.bat",
                    "--cf", "IE_Configurations.properties", "--tc",
                    "scripts\\testCases" };
            Process p = runtime
                    .exec(command, null, new File(tipBVTScriptsPath));
            p.waitFor();
            System.out.println(p.exitValue());
}

String[] command = { "cmd.exe", "/C", "start /WAIT",....
Start /WAIT is the main thing to be understood here which will wait for the launched batch script in the separate window to get completed.
Once all the actions in the batch are completed the window remains open.
Hence the main important point here is to have "exit" statement as the last statement in the batch script which runs as process.


0 comments to "wait for batch script to finish ran from java process"

Post a Comment

Who ever writes Inappropriate/Vulgar comments to context, generally want to be anonymous …So I hope U r not the one like that?
For lazy logs u can at least use Name/URL option which don’t even require any sign-in, good thing is that it can accept your lovely nick name also and URL is not mandatory too.
Thanks for your patience
~Krishna(I love "Transparency")
వీలయితే నాల్గు పోస్టులు ...కుదురితే ఒక కామెంటూ ...

Translate

Enter your email address:

Buffs ...

Visitors


hits counter
View My StatsCheck Google Page Rank

Add to Google Reader or Homepage

Bookmark and Share

Tags


Powered by WidgetsForFree