Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.glorb.com!postnews.google.com!fj19g2000vbb.googlegroups.com!not-for-mail From: Memo Newsgroups: comp.lang.java.programmer Subject: runtime.exec problems Date: Sat, 25 Jun 2011 10:58:27 -0700 (PDT) Organization: http://groups.google.com Lines: 58 Message-ID: NNTP-Posting-Host: 65.88.88.74 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1309024707 867 127.0.0.1 (25 Jun 2011 17:58:27 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 25 Jun 2011 17:58:27 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: fj19g2000vbb.googlegroups.com; posting-host=65.88.88.74; posting-account=ZUdoNgkAAABA4n8WF3dRL8pjnGa58W4a User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: ARLUEHNKC X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; GTB7.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.2; .NET4.0C; .NET4.0E),gzip(gfe) Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:5667 I can't get runtime.exec to execute a program in Java. I am trying to execute a bat file. I read that in order to run bat files as opposed to .exe files the runtime command has to include "cmd /c start" before the name of the bat file. I have run bat files successfully this way before. The command that I am running works when typed from the command line. It is: z:/n4/pkg/MrServers/MrVista/Simu/StartSimEnv.bat -AutoStart GOLD_256x512.dat When I try the following code: File file = new File(imageDir); cmd = "C:\WINDOWS\system32\cmd /c start "+simDir+"StartSimEnv.bat - AutoStart " + imageName; IJ.log("cmd = " + cmd); Runtime runtime = Runtime.getRuntime(); try{ Process proc = runtime.exec(cmd,null,file); } catch(Exception e) { IJ.log(e.toString()); } StartSimEnv.bat file gives a message about the usage being wrong as if I'm giving the wrong parameters. If I delete imageName from the cmd string it doesn't complain about usage but doesn't do the task I want it to do. I tried putting the parameters in an array as follows: File file = new File(imageDir); String[] cmdArray = {cmdPath, "/c", "start",simDir+"StartSimEnv.bat","- AutoStart",imageName}; IJ.log("cmdArray = " + cmdArray[0] + " " + cmdArray[1] + " " + cmdArray[2] + " " + cmdArray[3] + " " + cmdArray[4] + " " + cmdArray[5]); Runtime runtime = Runtime.getRuntime(); try{ Process proc = runtime.exec(cmdArray,null,file); } catch(Exception e) { IJ.log(e.toString()); } I still get a message about usage. I have made efforts with process builder also but can't get that to work either. Does anyone have any ideas why this isn't working?