Problem executing file through Runtime.exec

Hi,
i am trying to execute a java programem using the the following line
Runtime.exec("java Myclass");
But no response for it.
Anybody help me.
Jossy

As required by forum protocol for people who ask questions about Runtime.exec I am posting the standard link:
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

Similar Messages

  • Problem compiling file through Runtime.exec

    Hi all,
    I execute the following code :
    Runtime r = Runtime.getRuntime()
    Process p = r.exec("javac /home/test/temp dir/helloworld.java");
    The command i give has a directory with space ("temp dir"). Iam not able to run the above code in Linux.
    Kindly help me.
    Thanks in advance.
    Regards,
    Andy

    Runtime.exec have several signatures - use the method that receive String [] as command parameters - it should solve your problem since in every String will be considered as a separate parameter:
    Try the following:
    Runtime r = Runtime.getRuntime();
    String [] cmdArray=new String[2];
    cmdArray[0]="javac";
    cmdArray[1]="/home/test/temp dir/helloworld.java";
    Process p = r.exec(cmdArray);If it still won't work then you will probably need to use a method that receive also the environment.
    HTH

  • Error while running executable file through java in WinNT

    I would like to run an executable file with Java.
    - If I try with notepad or paint, i.e. Windows Applications,
      I have no problem.
    - I also can run Non-Windows-Own Applications, except one.
      I get an error message, if I want to run this program through Java.
    I have tried following commands to run an executable file.
    Runtime.getRuntime().exec("cmd.exe /c "+command);
    Runtime.getRuntime().exec("cmd.exe /c start "+command);
    Runtime.getRuntime().exec("cmd.exe /c start /wait "+command);
    Runtime.getRuntime().exec("cmd.exe /k start "+command);
    command : the path to the executable file
    I can run the application directly, if I click the icon on desktop,
    but not through Java.
    here is the error message I get
    screenshot : http://www.aykut.de/error_message.jpg
    Text : "Security Check failure"
            The Logon System has been tampered with.
            The Administrator will need to re-install.
    my Idea :
    The application is "old".
    I think it was written for Win 3.1.
    Therefore I don't know if there is any other
    possibilty to run a "DOS Exe File" through Java.

    I have just figured out how it works,
    if somebody else here in forum have this problem,
    here is the solution :
    String path = "F:\...\...\Application.exe";
    String envDir = path.substring(0, path.lastIndexOf("\\"));
    String[] command = {"cmd.exe", "/c", "start", "/wait", "/D"+envDir, path};
    Process process = Runtime.getRuntime().exec(command);
    "start /Dpath" => path: environment directory F:\...\...\
    "start /wait" => wait until Application.exe terminates
    if you use Win95 or Win98 use command.com instead of cmd.exe
    Aykut

  • How to capture output of java files using Runtime.exec

    Hi guys,
    I'm trying to capture output of java files using Runtime.exec but I don't know how. I keep receiving error message "java.lang.NoClassDefFoundError:" but I don't know how to :(
    import java.io.*;
    public class CmdExec {
      public CmdExec() {
      public static void main(String argv[]){
         try {
         String line;
         Runtime rt = Runtime.getRuntime();
         String[] cmd = new String[2];
         cmd[0] = "javac";
         cmd[1] = "I:\\My Documents\\My file\\CSM\\CSM00\\SmartQ\\src\\E.java";
         Process proc = rt.exec(cmd);
         cmd = new String[2];
         cmd[0] = "javac";
         cmd[1] = "I:\\My Documents\\My file\\CSM\\CSM00\\SmartQ\\src\\E";
         proc = rt.exec(cmd);
         //BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
         BufferedReader input = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
         while ((line = input.readLine()) != null) {
            System.out.println(line);
         input.close();
        catch (Exception err) {
         err.printStackTrace();
    public class E {
        public static void main(String[] args) {
            System.out.println("hello world!!!!");
    }Please help :)

    Javapedia: Classpath
    How Classes are Found
    Setting the class path (Windows)
    Setting the class path (Solaris/Linux)
    Understanding the Java ClassLoader
    java -cp .;<any other directories or jars> YourClassNameYou get a NoClassDefFoundError message because the JVM (Java Virtual Machine) can't find your class. The way to remedy this is to ensure that your class is included in the classpath. The example assumes that you are in the same directory as the class you're trying to run.
    javac -classpath .;<any additional jar files or directories> YourClassName.javaYou get a "cannot resolve symbol" message because the compiler can't find your class. The way to remedy this is to ensure that your class is included in the classpath. The example assumes that you are in the same directory as the class you're trying to run.

  • How to exec command with parameters through runtime.exec()

    im trying to run a command prompt passing in parameters. Right now im creating a .bat file like this
    c:
    cd C:\SOMEDIR
    ant deploy moreparameters
    and then passing in the file name into the exec command. It is running fine but im trying to use the runtime.destroy() command and it doesnt close the ant command, it only closes the bat file which was already closed. Is there a command I could pass into the exec() method to run the ant command with the parameters without using a bat file?

    im getting a CreateProcess: ant deploy -Dswasm=swasm error=2
    When i try to do
    cmds[0] = "ant";
    cmds[1] = "deploy";
    cmds[2] = "-Dswasm=all-bs";
    Process p = runTime.exec(cmds, null, new File("C:\\Program Files\\apache-ant-1.6.1\\bin"));
    its like it cant find ant. But it finds java command fine. What should i pass into the second parameter, it says "If envp is null, the subprocess inherits the environment settings of the current process. " Does that mean it will take the window system enviroment variables? if not what string would i pass in to set where ant is?

  • Problem in opening a doc file using Runtime.exec()

    Code:
    import java.io.*;
    class StreamGobbler extends Thread {
        InputStream is;
        String type;
        StreamGobbler(InputStream is, String type) {
            this.is = is;
            this.type = type;
        public void run() {
            try {
                InputStreamReader isr = new InputStreamReader(is);
                BufferedReader br = new BufferedReader(isr);
                String line=null;
                while ( (line = br.readLine()) != null) System.out.println(type + ">" + line);   
            catch (IOException ioe) {
                 ioe.printStackTrace(); 
    public class GoodWindowsExec {
        public static void main(String args[]) {
             String file = "test.doc";
             String appPath = "/C";
            try {
                String osName = System.getProperty("os.name" );
                System.out.println("OS : " + osName);
                String[] cmd = new String[3];
                if( osName.equals( "Windows NT" ) || osName.equals( "Windows XP" )) {
                    cmd[0] = "cmd.exe" ;
                    cmd[1] = appPath;
                    cmd[2] = file;
                else if( osName.equals( "Windows 95" ) ) {
                    cmd[0] = "command.com" ;
                    cmd[1] = appPath;
                    cmd[2] = file;
                Runtime rt = Runtime.getRuntime();
                System.out.println("Execing " + cmd[0] + " " + cmd[1] + " " + cmd[2]);
                Process proc = rt.exec(cmd);
                // any error message?
                StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "ERROR");           
                // any output?
                StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "OUTPUT");
                // kick them off
                errorGobbler.start();
                outputGobbler.start();
                // any error???
                int exitVal = proc.waitFor();
                System.out.println("ExitValue: " + exitVal);       
            catch (Throwable t) {
                t.printStackTrace();
    }I got this code from internet. Program will work fine if my "test.doc" is in "C:\test.doc" directory. Is there any way to get the application path and open the doc file or how to give a specified path for my doc file
    EG:- "C:\TestDir\test.doc"
    Thanks

    Well /C is not the path to the app. It is a switch to
    the command line.
    set your file name to "C:/test.doc"
    ~TimSorry, I guess my reply doesn't really answer the problem. But you can supply the entire path as part of the file name string.
    String file = "C:/Path/To/My/File/to execute/test.doc"

  • Problem wiht Running Batch File using Runtime.exec()

    I am writting one program which will create a jar file using a windows Batch file.
    The main program is in the folder "d:\CmdExec.java".
    The other one to which a jar file to be created is in the folder "e:\folder\HelloWorld.class"
    The contents inside the "e:\folder" are
    e:\folder\HelloWorld.class
    e:\folder\mainClass.txt
    e:\folder\run.bat
    The mainClass.txt contains "Main-Class: HelloWorld"
    The Run.bat file contains "jar cmf mainClass.txt HelloWorld.jar *.class"
    The coding for CmdExec.java is as follows
    import java.io.*;
    import java.awt.Desktop;
    public class CmdExec {
    public static void main(String argv[]) {
    try {
    Desktop desktop = null;
    if (Desktop.isDesktopSupported()) {
    desktop = Desktop.getDesktop();
    desktop.open(new File("e:\\folder\\run.bat"));
    catch (Exception err) {
    err.printStackTrace();
    When i double click the file e:\folder\Run.bat, it will create a jar file for HelloWorld.class.
    But, i want to create that jar file using the java program CmdExec.java.
    When i run CmdExec.java, the batch file is opened. But it shows error as "Can't find the specified file"
    But when i copy the following files to "d:\",
    e:\folder\HelloWorld.class
    e:\folder\mainClass.txt
    the jar file is created using the CmdExec.java.
    But,
    e:\folder\HelloWorld.class
    e:\folder\mainClass.txt
    these files should be in the folder"e:\folder" only.
    Can anyone Help me this Problem?
    Or Anyother way for creating a jar file for one program by using another program?
    Help me soon.............

    Try this. It's not running a bat file. You can say it almost is a bat file.
    import java.io.*;
    import java.util.Scanner;
    public class CmdExec {
        public static void main(String argv[]) {
            try {
                Process p = Runtime.getRuntime().exec("jar cmf mainClass.txt HelloWorld.jar *.class");
                Scanner s1=new Scanner(new InputStreamReader(p.getInputStream()));
                while(s1.hasNextLine())
                    System.out.println(s1.nextLine());
                p.waitFor();
                System.out.println(p.exitValue());
                if(p.exitValue()==0)
                    System.out.println("Okay");
                else
                    System.out.println("Error");
            catch (Exception ex) {
                ex.printStackTrace();
    }Run it in the same folder as mainClass.txt
    Edited by: ColacX on Aug 1, 2008 10:35 AM

  • Problem opening a file from Runtime.exec()

    hi
    I'm trying to open a certificate (.cer), from my java code.
    If I go on a windows command, and I type only the name of my certificate ( f:\certificate.cer), it is opened.
    If I use the java code
    Process process = Runtime.getRuntime().exec("F:\\certificate.cer");it doesn't work:
    java.io.IOException: CreateProcess: "f:\oid.crt" error=193
    anybody knows what I can do to make it work?
    Thanks in advance
    Philippe

    For windows you need to used the cmd.exe to do what you want.
    i.e. cmd /c f:\certificate.cer
    Process process = Runtime.getRuntime().exec("cmd.exe /c F:\\certificate.cer");At a command prompt, for more help on cmd.exe type: cmd /?
    Also for help on a related command, type: start /?
    Also read http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • Problems running program using Runtime.exec()

    Hello everyone. I have a quick problem that perhaps someone can help me with... I'm trying to write a frontend for a command line program. I've found plenty of examples for using exec() to launch this program but I can't quite get the effect that I desire. The program itself launches it's own window (using a graphics library called SDL) but the user interacts with the program through the command prompt.
    The problem that I'm having is that my InputStream thread does not seem to execute until I close the SDL window. I've tried about 10 different combinations of threading this application but nothing seems to work.
    Below I've attached some sample code that I found here on the Sun site... The code does as I described before, the InputStream does not display any text until I close the SDL window.
    Can anyone help out?
    import java.io.*;
    // class StreamGobbler omitted for brevity
    class StreamGobbler extends Thread
    InputStream is;
    String type;
    OutputStream os;
    StreamGobbler(InputStream is, String type)
    this(is, type, null);
    StreamGobbler(InputStream is, String type, OutputStream redirect)
    this.is = is;
    this.type = type;
    this.os = redirect;
    public void run()
    try
    PrintWriter pw = null;
    if (os != null)
    pw = new PrintWriter(os);
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);
    String line=null;
    while ( (line = br.readLine()) != null)
    if (pw != null)
    pw.println(line);
    System.out.println(type + ">" + line);
    if (pw != null)
    pw.flush();
    } catch (IOException ioe)
    ioe.printStackTrace();
    public class TestExec
    public static void main(String args[])
    if (args.length < 1)
    System.out.println("USAGE: java TestExec \"cmd\"");
    System.exit(1);
    try
    String cmd = args[0];
    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec(cmd);
    // any error message?
    StreamGobbler errorGobbler = new
    StreamGobbler(proc.getErrorStream(), "ERR");
    // any output?
    StreamGobbler outputGobbler = new
    StreamGobbler(proc.getInputStream(), "OUT");
    // kick them off
    errorGobbler.start();
    outputGobbler.start();
    // any error???
    int exitVal = proc.waitFor();
    System.out.println("ExitValue: " + exitVal);
    } catch (Throwable t)
    t.printStackTrace();

    I'm pretty sure, because if you run the application without any parameters you don't get the SDL window, you just get a list of possible command line switches, that part works fine... It just seems that when the SDL window is open, the thread won't grab and display the individual lines until that window is closed, which will not work for my purposes...

  • Executing .cmd with Runtime.exec()

    I'm trying to run a file with the following cod:
    Runtime rt = Runtime.getRuntime();
    String[] command = {"cmd.exe", "/c", "start", "c:\\Documents and Settings\\Rahul Shroff\\Desktop\\svn\\trunk\\c\\rahul_facedetect.cmd"};
    try{
             Process proc = rt.exec(command);
    catch(Exception e) {System.out.println("error with proc" + e.getMessage());}With the code, a command prompt is opened, but my .cmd file is not. Does anyone know how to fix this? Please don't send me a link to the "When Runtime.exe() Won't" ; I have already looked through this. Thanks!

    Okay, I tried that, and the code compiled fine, but I got this runtime error:
    error with procCreateProcess: "C:\Documents and Settings..." error = 123
    My code is :
    Runtime rt = Runtime.getRuntime();
        String[] command = {"C:\\Documents and Settings\\Rahul Shroff\\Desktop\\svn\\trunk\\c\\rahul_facedetect.exe --cascade=C:\\Documents and Settings\\Rahul Shroff\\Desktop\\svn\\trunk\\OpenCV\\data\\haarcascades\\haarcascade_frontalface_alt.xml"};
        try{
             Process proc = rt.exec(command);
             System.out.println("tried to execute .cmd");
        catch(Exception e) {System.out.println("error with proc" + e.getMessage());}
      }I am sure that the command C:\Documents and Settings... works; I've tried it separately in a command prompt. Any suggestions? Thanks for the help!

  • Opening a file via Runtime.exec() on Mac OS X

    I'm having a hard time opening a file programatically on Mac OS X.
    The following code works only if the filepath/filename doesn't contain a space:
    String filepath;
    Runtime rt = Runtime.getRuntime();
    rt.exec( "open " + filepath);From a terminal, typing open + surrounding the filepath with either apostrophes or quotes and OS X will open the file no problem, even if it has spaces.
    So I tried modifying my call:
    filepath = "\"" + filepath + "\"";
    rt.exec( "open " + filepath);...then nothing happens. No error, no popup, no exception thrown...nothing. Same thing if I use apostrophes vice quotes.
    Any ideas? I'm using JDK 5.0 as 6.0 is not yet supported by Apple.
    Thanks in advance.

    assuming open is an app, not a command within a shell... what about this:
    String[] cmd = { "open", filepath }; // with out quotes
    rt.exec(cmd);

  • Running an executable file through servlet

    Hello People,
    I tried searching about this on the Forums, but could not find the right solution.
    Please donot get annoyed if you find this to be a repeted topic, which I am sure is not.
    I want to run a .sh file in Unix environment through servlet.
    Actually i want to do this inorder to schedule a report servet to run a report and generate the output in a particular format on a click of a button.
    I tried using Runtime.getRuntime().exec method, (which I know through forum is unreliable)
    Can anyone suggest me a method through I can achieve this?
    Any suggestion is appreciated.
    Regards,
    Rohan Kamat

    Hi MOD,
    Thanks for the quick reply.
    Heres what I am doing to schedule.
    1) The client selects the necessary parameters from the front end and then saves it in a table.
    2) This he will be doing for as many reports as he wants, on an average there will be 200 reports daily.
    3) Once he has selected all the parameters for all the reports, he will go to the next screen and fire a script to run the reports at a time.
    4) This script will be fired only once. And once it is fired it will generate a PDF files of the reports.
    5) On the front end the screen will be refreshed showing the users the status of the reports that he has scheduled to be run
    I am using Servlets 2.0 version, and jdk.12
    Regards,
    Rohan Kamat

  • Moving files with Runtime exec of command

    Hello,
    I'm trying to make a file overwrite another. From command line this is easy,
    move /Y c:\\somedir\\somefile.txttmp c:\\somedir\\somefile.txt(assuming DOS)
    Trying to use
    String cmd = "move /Y c:\\somedir\\somefile.txttmp c:\\somedir\\somefile.txt"
    Process proc = Runtime.getRuntime.exec(cmd);And it throws me an IOException saying error=2. Not sure what that means, was hoping someone here might. Thanks a lot!

    Reading and writing. There is no move. You might try java.nio.channels.FileChannel:
    [http://java.sun.com/javase/6/docs/api/java/nio/channels/FileChannel.html#transferTo(long,%20long,%20java.nio.channels.WritableByteChannel)]
    But I didn't find that any faster for me. YMMV.
    edit: Oh yes, there is a File.renameTo:
    [http://java.sun.com/javase/6/docs/api/java/io/File.html#renameTo(java.io.File)]

  • How to start microsof access with parameter through runtime.exec

    Hi,
    I try to start access with parameter like this:
    String[] cmd = new String[4];
    cmd[0] = "C:\\Programme\\Microsoft Office\\OFFICE11\\MSACCESS.EXE";
    cmd[1]= "C:\\MyDB.mdb ";
    cmd[2] = "/cmd";
    cmd[3] = "parameter1 parameter2";
    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec(cmd);
    However the access mdb startet but it seems not to take the parameter i want to put in to access.
    Have anyone an Idea, what is wrong here?
    Thanks

    Hi
    What do you expect Access to do?
    The /cmd command line option sets the value that is returned by VBA Command function (see http://msdn2.microsoft.com/en-us/library/aa211469(office.11).aspx).
    If you want to start a macro, you would need the /x switch (see http://office.microsoft.com/en-us/access/HA101666051033.aspx).
    Hope this helps
    Christoph

  • How to open an .txt file or .doc file using Runtime.exec()?

    Thanks

    Do:String[] cmdLineArray = new String[3];
    cmdLineArray[0] = "cmd.exe";
    cmdLineArray[1] = "/c";
    cmdLineArray[2] = yourCompletePathFile;
    Runtime.getRuntime().exec(cmdLineArray);

Maybe you are looking for

  • Specific question on video capabilities

    My house mate has some disabilities. She has a PC in her bedroom with a nice 17 in LCD monitor on a cart for when she is sick (frequent). I have an iMAC and am afraid that touting its praises has led her to want a Apple computer. It would make sense

  • Single Supplimentary Invoice for Multiple Invoices

    Hi We are having Standardmanufacturing sales Process Ex: We did the sales of 1000 quantity of  goods over the period of time for Price  100 Rs/ and we had created invoices also in the system .After 3 months with the customer on mutual undersating we

  • Is it ok to turn off my macbook pro 2011

    I would like to know if its ok to turn off my macbook pro 2011 every time its not in use , and its not connect to a power source .

  • How to enter password to unlock iPad after finding it

    I lost my iPad and used Find My IPhone app to lock it.  I found it and can't figure out how to use the password to unlock access to the internet

  • Unable to store data into the Table(R/3)

    Dear All, our requirment is to store few records into the Table in R/3. We have update RFC which takes input arguments as AbstractList , the following is the code used to store data in the table(R/3) Zhr_Update input = new Zhr_Update(); AbstractList