Have you tried option B "start"?
proc = Runtime.getRuntime().exec("cmd /c start /B somebat.bat");
Edit:
Ok, Anish, it's funny that your code is not executing.
I installed unit test:
Process proc = null; try { proc = Runtime.getRuntime().exec("cmd /c start /BD:\\temp\\_test\\somebat.bat"); proc = Runtime.getRuntime().exec("cmd /c call D:\\temp\\_test\\somebat.bat"); proc = Runtime.getRuntime().exec("D:\\temp\\_test\\somebat.bat"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }
My somebat.bat file looks like this:
rem somebat.bat: d: cd D:\temp\_test copy somebat.bat somebat2.bat
All three versions in the try block above work in my script. Somebat.bat is copied to the somebat2.bat file without the command window appearing (what happens if I use your call specified in your question).
Edit 2: Next round ;-)
Anish, can you show us what your somebat.bat file and your ant file look like?
Since all three calls below work in my scenario:
test code:
Process proc = null; proc = Runtime.getRuntime().exec("cmd /c start /B c:\\temp\\_test\\somebat.bat"); proc = Runtime.getRuntime().exec("cmd /c call c:\\temp\\_test\\somebat.bat"); proc = Runtime.getRuntime().exec("c:\\temp\\_test\\somebat.bat");
somebat.bat:
cd\temp\_test ant mycopy
build.xml:
<?xml version="1.0"?> <project name="testproj" default="mycopy" basedir="."> <target name="mycopy"> <copy file="myfile.txt" tofile="mycopy.txt" /> </target> </project>
myfile.txt: custom text file
source share