You think running a bat file with Java will be an easy task, but no ... I have a bat file that executes some sql commands to loop values ββread from a text file. This is something like this:
FOR /F %%x in (%CD%\listOfThings.txt) do sqlcmd -Slocalhost\MSSQL %1 %2 -d %3 -i %CD%\SQLScripts\\%%x exit
Do not worry about the specifics in which they are not important. I want to just run this bat file from Java and wait for it to complete. This is apparently not easy. What I still know:
Runtime.getRuntime().exec("cmd /K start SQLScriptsToRun.bat" +" -U"+getUser() +" -P"+getPass() +" " + projectName); return true;
The problem is that the exec () method returns immediately. The bat file runs for 2-3 minutes. I tried to remove the beginning, but to no avail. I have tried many options, but this is of no use. Any ideas on how to do this simple task?
source share