Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

execute a batch file

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
How do I execute a batch filr from a java application?
I have tried:
String sLocation = "X:\\Java\\WSAD\\workspace\\xrad2\\webApplication\\xrad\\config\\startup.bat";
Runtime rt = Runtime.getRuntime();
try
{
rt.exec(sLocation);
System.out.println("Process: " + sLocation );
}
catch(IOException e)
{
Logger.logError("IOException starting process! Location: "+sLocation);
e.printStackTrace();
}
But I get the following error:
ERROR: IOException starting process! Location: X:\Java\WSAD\workspace\xrad2\webApplication\xrad\config\startup.bat
java.io.IOException: CreateProcess: X:\Java\WSAD\workspace\xrad2\webApplication\xrad\config\startup.bat error=193
at java.lang.Win32Process.create(Native Method)
at java.lang.Win32Process.<init>(Win32Process.java:70)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.exec(Runtime.java:568)
at java.lang.Runtime.exec(Runtime.java:433)
at java.lang.Runtime.exec(Runtime.java:376)
at java.lang.Runtime.exec(Runtime.java:340)
at com.orygen.xrad.util.RuntimeExec.execute(RuntimeExec.java:45)
at com.orygen.xrad.webenvironment.ExradProcessor.startupXrad(ExradProcessor.java:2265)
at com.orygen.xrad.webenvironment.ExradProcessor.initialise(ExradProcessor.java:274)
at com.orygen.xrad.webenvironment.ExradControllerServlet.init(ExradControllerServlet.java:41)
at javax.servlet.GenericServlet.init(GenericServlet.java:258)
at com.ibm.servlet.engine.webapp.StrictServletInstance.doInit(ServletManager.java:802)
at com.ibm.servlet.engine.webapp.StrictLifecycleServlet._init(StrictLifecycleServlet.java:141)
at com.ibm.servlet.engine.webapp.PreInitializedServletState.init(StrictLifecycleServlet.java:254)
at com.ibm.servlet.engine.webapp.StrictLifecycleServlet.init(StrictLifecycleServlet.java:107)
at com.ibm.servlet.engine.webapp.ServletInstance.init(ServletManager.java:388)
at javax.servlet.GenericServlet.init(GenericServlet.java:258)
at com.ibm.servlet.engine.webapp.ServletManager.addServlet(ServletManager.java:84)
at com.ibm.servlet.engine.webapp.WebAppServletManager.loadServlet(WebAppServletManager.java:226)
at com.ibm.servlet.engine.webapp.WebAppServletManager.loadAutoLoadServlets(WebAppServletManager.java:357)
at com.ibm.servlet.engine.webapp.WebApp.loadServletManager(WebApp.java:1010)
at com.ibm.servlet.engine.webapp.WebApp.init(WebApp.java:133)
at com.ibm.servlet.engine.srt.WebGroup.loadWebApp(WebGroup.java:234)
at com.ibm.servlet.engine.srt.WebGroup.reload(WebGroup.java:1033)
at com.ibm.servlet.engine.srt.ClassChangeWatcher.classChanged(ClassChangeWatcher.java:55)
at com.ibm.ws.classloader.ClassLoaderManager.checkAndNotify(ClassLoaderManager.java:380)
at com.ibm.ws.classloader.ClassLoaderManager.alarm(ClassLoaderManager.java:291)
at com.ibm.ejs.util.am.AlarmThread.run(AlarmThread.java:56)
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Error 193 is ERROR_BAD_EXE_FORMAT, because a .bat file isn't an executable. You've got to start cmd.exe and tell it to run the batch file -- i.e.,
exec("cmd /c path\\to\\foo.bat").
 
Blikkies Marais
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Thanks for the response, but I still have a problem. I try the following:
rt.exec("cmd X:\\Java\\WSAD\\workspace\\xrad2\\webApplication\\xrad\\config\\startup.bat");
It executes a dos prompt, but does not execute the batch file. But I don't get any Exception.
I have also tried:
rt.exec("cmd /c X:\\Java\\WSAD\\workspace\\xrad2\\webApplication\\xrad\\config\\startup.bat");
But this does not execute the batch file either. Have you any suggestions?
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
For the record, note that this does work -- he's just not seeing the output he expects. See this follow-up thread.
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Uh oh. This conversation in two places could get a bit confusing. I'm closing this thread, and let's continue the conversation over in the Intermediate forum.
 
    Bookmark Topic Watch Topic
  • New Topic