Cannot run batch program from Java Application

Hi All,
Im trying to run a batch file under windows from my Java Program. The batch file is located in the following path:
C:\Program Files\MyApp\runme.bat
The above-entioned path contains white space which is not allowed in NT.
Im trying following code:
import java.io.*;
public class Exec {
public static void main(String args) {
try {
Runtime.getRuntime().exec("cmd /c start C:/Program Files/MyApp/runme.bat");
}catch(Exception ex){ ex.printStackTrace();}
How to run this file?
Thanks in advance.
Ketan Malekar

or use the overload that takes an array of strings as argument
String[] command = {"cmd", "/c", "start", "C:/Program Files/MyApp/runme.bat");
Runtime.getRuntime().exec(command);

Similar Messages

  • Can we run EXE file/ Another Java Program from Java Application? How?

    Can we run EXE file and another java program from java application?
    Thanks in advance

    Example running adobe acrobat
    String command = "C:\\Program Files\\Adobe\\Acrobat 5.0\\Reader\\AcroRd32.exe /t "+selectedDocument+" \\\\CONTROL\\HP LaserJet 4L";
    Runtime rn = Runtime.getRuntime();
    Process process = rn.exec(command);
    process.waitFor();rykk

  • Running exe files from java applications

    Hello All,
    Is it possible to run executable files from java applications?
    I need to run an exe file on the client from the server machine, the exe could reside on either the server or any other machine on the LAN. Is it possible to specify the path of where the exe resides, and run it on a client machine?

    HI,
    I tried to launch a MS Word application using runtime.exec but it gives me some problem
    The foll. code to launch a txt file using notepad works.
    Runtime rt = Runtime.getRuntime();
    String[] callAndArgs = {"notepad.exe","C:\\coo7\\wizard.txt"};
    Process child = rt.exec(callAndArgs);
    However, oif I try to launch a MS Word application, it asks for the entire path of WINWORD.exe, (unlike just specifying notepad.exe as the first argument in String[] callAndArgs) and this can vary from one machine to another.. how do I get around this?
    The foll. code snippet works but the complete path of where WINWORD.exe might be installed on any machine, is not fixed:-(
    Runtime rt = Runtime.getRuntime();
    String[] callAndArgs = {"C:\\Program Files\\Office\\Office10\\WINWORD.exe","C:\\coo7\\wizard.doc"};
    Process child = rt.exec(callAndArgs);
    Any idea/suggestions pls..

  • Running Chuck program from iphone application

    Hi,
    I am trying to integrate chuck to my iphone application. How I can do this.?
    I want to run one chuck program from iphone application.
    Regards,
    Ganesh Pisal
    Vavni Inc.

    Expect to get a lot of problems as embedding Java GUI application into native X GUI application is very complicated process which usually requires clear understanding of design of AWT native code for X. One of the problems is events sharing, another is X resource sharing. If you could provide more details on design of your program and interaction with Java we might try to at least estimate hardness of the problems and possibility of such an implementation at all.
    The questions are:
    1) Does you program uses the same X display connection as Java?
    2) What kind of X toolkit are you going to use?
    3) How are you going to embed Java windows into you X windows(if at all)?
    4) Are you going to use Java X window(or widgets) from your program or you are going to use JNI and Java to interact with them through Java?

  • Error running batch files from java source file???

    Dear Friends,
    hi,
    this is with response to a doubt i had earlier ,
    i want to run batch files from the java source file ,i tried using this code (here batrun is the batch file name that contains commands to run other java files)
    try
    String [] command = {"c:\\vishal\\finalmain\\batrun"};
    Runtime.getRuntime().exec(command);
    catch(Exception e)
    but i got the following error.
    java.io.IOException: CreateProcess: gnagarrun error= 2
    plz. help me, i tried all combination w/o success,
    in anticipation(if possible give the code after testing)
    Vishal.

    hello there,
    i solved the prob. by using
    cmd /c start filename ,but i need to pass parameters ie
    cmd /c start java "c:/vishal/runfile a b" where a and b are the parameters. but it is not accepting this in Runtime.getRuntime.exec(),
    any solutions ?????????
    regards,
    Vishal

  • Running a script from java application

    How do I execute a script (sms_setver which requires parameters such ms9qa) from java application using Runtime.exec(). I tried Runtime.getRuntime().exec("sms_setver ms9qa"). But, I get this error:
    Caught: java.io.IOException: CreateProcess: sms_setver ms9qa error=2

    Same way it is actually run from a console command line.
    If you are doing this in windows then it might be using the extension to determine how to run it. If from unix then it might be using the shebang line.
    At any rate figure it out and use that instead. Usually it involves either explicitly using the shell or some other executable and the script is a parameter to that process.

  • Run a program from java code

    I want to run this program from my java code,
    In Linux(ubuntu) I write this command to open the program window
    $ paraFoam -case /home/saud/OpenFOAM/OpenFOAM-1.5/run/tutorials/icoFoam/cavity/In my java code I wrote it like this("/home/saud/OpenFOAM/OpenFOAM-1.5/bin/" is the path of the program):
    String command = "/home/saud/OpenFOAM/OpenFOAM-1.5/bin/paraFoam " +
              "-case /home/saud/OpenFOAM/OpenFOAM-1.5/run/tutorials/icoFoam/cavity/";
    final Process myProcess = Runtime.getRuntime().exec(command);
    BufferedReader buf = new BufferedReader(new InputStreamReader(
              myProcess.getInputStream()));
    String line;
    while ((line = buf.readLine()) != null) {
         System.out.print(String.format("%s\t\n", line));
    buf.close();
    int returnCode = myProcess.waitFor();
    System.out.println("Return code = " + returnCode); Return code = 0
    but the program is not opening
    Edited by: Saud.R on Apr 11, 2009 3:37 AM

    Welcome to the Sun forums.
    I am not sure of the answer to your question, but people who use Processes regularly, warn other users to ensure they are also doing something with the error stream of the process, otherwise it can hang as you describe.

  • Running batch files  from Java using exec method

    Hi,
    I want to run a batch file from my Java program like this:
    try {
    Process proc = Runtime.getRuntime().exec("C:\\Refresh.bat");
    catch (Exception e) {
    MessageBox.show(e.getMessage());
    Refresh.bat file contains two commands.
    First one unzips certain zip file.
    Second one refreshes a SQL Server database using osql utility.
    Problem is that when program is run it executes only the first command and hangs on the second one.
    Please help.
    TIA
    Ravinder

    From the FAQ:
    2. How do you launch an external program on a Microsoft Windows platform from a program developed on the Java [tm] programming language?
    The following will launch notepad in Microsoft Windows NT:
    Runtime.getRuntime().exec("cmd /c notepad.exe");
    To launch a program in Microsoft Windows 95/98 use:
    Runtime.getRuntime().exec("c:\\windows\\notepad.exe");
    The Runtime class allows interaction between a program and its environment. The first string command instructs the command line interpretor, cmd to open up the calculator application.
    The exec() methods do not use a shell; any arguments must have the full pathname to the shell as well as the command itself.
    For example, to run a shell on the UNIX� platform, type:
    Runtime rt = Runtime.getRuntime();
    Process p = rt.exec("/usr/bin/sh -c date");
    To run a batch file under Microsoft Windows 95/98:
    Process p = rt.exec("command.com /c c:\\mydir\\myfile.bat");
    To run a batch file under Microsoft Windows NT:
    Process p = rt.exec("cmd /c c:\\mydir\\myfile.bat");
    where 'cmd' and 'command.com' are the command-line interpreters for Microsoft Windows machines.
    The Runtime.exec() methods might not work effectively for some processes on certain platforms. Special care should be taken with native windowing, daemon, WIN16/DOS process or some shell scripts.
    regards,
    jarshe

  • Running .bat files from java applications

    Has anyone tried to run a .bat file from a java application?
    I know I can run java commands by getting the application's runtime, but I've a number of *.bat files I like to run from the application without having to extract the commands from the .bat files.
    thks,

    Crikey! You were answered very shortly after you posted your question, and you STILL haven't bothered to come back. And are you going to create a new userid the next time you ask a question, since bat2004 seems tied to this particular question?

  • Running a program from Java

    how do i launch one Java program from another?
    both .class files and the JRE directory are in the same directory

    You can use Runtime.exec() to run it as a seperate process, or you can always instantiate your secondary class. Do a search on the term "runtime.exec()" befure you go spawning another thread asking how to use it. That particular subject has been done to death many times already.

  • How to run a vi from Java application?

    I am passing data to a vi from my java swing application using data socket bean but I have to manually open and run the vi. How can I programatically open and run the vi from my java application without using ActiveX automation server?

    I don't know Java but if you can issue a shell command then you can run the VI with the command line:
    "\labview.exe" ""
    You have to set the VI to "Run when opened". The VI will run each time the command is issued, even if the VI is already opened.
    LabVIEW, C'est LabVIEW

  • Problems running external programs from java

    Hello.
    I wrote a pair of perl scripts and a GUI in java to run them. The first perl script just read the files in one directory makes some changes to the names of the files and then group all this files in a set of new directories. The other perl scripts takes all this new files and calls BLAST sequence alignment program and perform some alignments among these sequences. I tested this scripts and they work fine.
    The problem comes when I try to run them for the JAVA GUI. I use RunTime and when I need to run the first perl script it all works well, but when The call to the second perl script is made the program fisishes without doing anything at all. I found out that the problem is that when running the script from the Java GUI it's not able to find BLAST program. So I guess that Java is not really starting a terminal session and it doesn't read my bash_profile to find out the path to my programs.
    So, my question is if anyone knows a method to tell Java to load all this paths in the bash_proflie file so all of my scripts work???.
    I have no idea is this can be done and how so any advice would be really wellcome.
    By the way, my java version is 1.4.2 and my OS is Mac OS X 10.3
    Thanks a lot , Julio

    Invoke /bin/sh -c and give it your program's full path with.
    (To understand what I've written, maybe reading
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps_p.html
    http://mindprod.com/jgloss/exec.html
    and
    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html
    (especially the exec(String[] cmdarray) method)
    might help)
    -T-

  • Run windows services from java application

    can java application run a windows server
    i have a web server that runing using tomcat and mysql
    can i make a icon in the systray
    that give me the option to (using a menu)
    run the server ,wicth means : tomcat and mysql are runing
    stop the server
    get tomcat stacktrace in a window
    i was thinking about runing tomcat and mysql as services
    and write the systray application using java,
    the systray application should acces window services ,
    and run/stop requierd services.
    what happend on a machine thar runs linux?
    thanks
    shay

    Ok .so it's will be a diffrent way under linux..
    for systray i will use http://systray.sourceforge.net/
    and for services i'll use the
    "net start <Service>" and "net stop service"
    i need to keep track on the service status
    so my Systray status will be updated
    what is the command for getting the status of the proccess
    thanks shay

  • How to run windows program through java applications.

    pls help me!!!!! code RED!~

    C:\Documents and Settings\student\Desktop\Running.java:12: cannot resolve symbol
    symbol : variable JMStudio
    location: class Running
    String path="C:/Program Files/MF2.1.1/bin"+JMStudio;
    ^
    1 error
    this error is generated
    any idea on how to solve it?

  • Run a program from java

    hi
    i have a program with extension .rcw and i want to run from a java program. can anyone show me the code that can help me to call this type of files or any type of files
    Thanks in advance.

    **  Here is a pure Windows solution
    **  Run the code and you will be taken to a tutorial
    that may provide
    **  a more generic solution
    public class WindowsProcess
         public static void main(String[] args)
              throws Exception
              String[] cmd = new String[4];
              cmd[0] = "cmd.exe";
              cmd[1] = "/C";
              cmd[2] = "start";
    cmd[3] =
    =
    "http://www.javaworld.com/javaworld/javatips/jw-javati
    p66.html";
    //          cmd[3] = "notepad";
    //          cmd[3] = "will.xls";
    //          cmd[2] = "a.html";
    //          cmd[3] = "file:/c:/java/temp/a.html";
    Process process = Runtime.getRuntime().exec( cmd
    md );
    }i really don't know what to say. You really help me.
    I'm really thankfull to you

Maybe you are looking for

  • How to burn songs from one itunes account to import into a new itunes acct

    I have set up seperate playlists for my children under my itunes account. However, my son is now older and receiving itunes gift cards and we want to set up his own itunes account but don't want to loose the songs we have purchased for him under my i

  • No Airprint in the Share Menu!

    if i press the share icon in any of the apps that  there is no print option in photos are only the "send as e-mail" and "wallpaper" option

  • Java functions with Oracle 10g

    I have browsed through other related message threads on this forum and it seems that the general recommendation is to develop stored procedures and functions using PL/SQL. I need to implement a set of functions that perform date related processing an

  • The ITunes store crashes everytime i start it up

    Everytime i want to open the ITunes store, it immediately crashes. It has been doing it ever since i have downgraded ITunes to ITunes 10, i know probably the eazyest option is up upgrade again to ITunes 11 but to be honest, i hate the new layout of I

  • TROUBLE SHOOTING DURING THE CHARGING

    I bought Nokia N1600 one year ago. But now when I charging the Phone for around 5 Min it's getting overheating and the display screen is getting blackish around the surface of display screeen. Waiting for reply Nagesh