Using runtime to invoke IE

2 questions:
1. I'm trying to do this:
          try {
               Runtime.getRuntime().exec("iexplore -new \"http://www.google.com\"");
          } catch (IOException iox) {But I get an IOException saying
java.io.IOException: CreateProcess: iexplore -new "http://www.google.com" error=2
I tried running the command just by clicking start->run and using the same string, and this worked
Can anyone help me figure this out?
Question 2:
I'd like to be able to later change the url that IE is showing, for instance if the user clicks on something else in my program. It's not urgent, but does anyone know how I can do that?

A: Using runtime to invoke IE

Any knowledge about the second part (loading a new URL
in the same window)Here's a crappy demo of a workaround:
try {               
  final String cmd = "C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE http://www.sun.com";
  final String cmd2 = "C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE http://www.google.com";
  Process p = Runtime.getRuntime().exec(cmd);
  Thread.currentThread().sleep(5000);
  p.destroy();
  p = Runtime.getRuntime().exec(cmd2);
} catch (IOException iox) {
  iox.printStackTrace();
}

Any knowledge about the second part (loading a new URL
in the same window)Here's a crappy demo of a workaround:
try {               
  final String cmd = "C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE http://www.sun.com";
  final String cmd2 = "C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE http://www.google.com";
  Process p = Runtime.getRuntime().exec(cmd);
  Thread.currentThread().sleep(5000);
  p.destroy();
  p = Runtime.getRuntime().exec(cmd2);
} catch (IOException iox) {
  iox.printStackTrace();
}

Similar Messages

  • How to invoke the command interpreter to run the "NS.exe" using Runtime?

    hi,everyone
    I need to invoke the command interpreter,and enter the disk directory "c:/ns2/bin/",then run the "ns myfilename" command.My program is followed:
    try{
    String s[]=new String[4];
    s[0]="cmd.exe";
    s[1]="/c";
    s[2]="cd c:/ns2/bin";
    s[3]="ns.exe c:/ns2/bin/100n-500k-5.tcl";
    Runtime R=Runtime.getRuntime();
    Process p=R.exec(s);
    int exitVal = p.waitFor();
    System.out.println("Process exitValue: " + exitVal);
    But this doesn't work!
    please help me! thanks!

    hi,everyone
    I need to invoke the command interpreter,and
    and enter the disk directory "c:/ns2/bin/",then run
    the "ns myfilename" command.My program is followed:
    try{
    String s[]=new String[4];
    s[0]="cmd.exe";
    s[1]="/c";
    s[2]="cd c:/ns2/bin";
    s[3]="ns.exe c:/ns2/bin/100n-500k-5.tcl";
    Runtime R=Runtime.getRuntime();
    Process p=R.exec(s);
    int exitVal = p.waitFor();
    System.out.println("Process exitValue: " +
    alue: " + exitVal);
    But this doesn't work!
    please help me! thanks!CDing will not change the directory.
    should write:
    String cmd= "cmd /c c:\\ns2\\bin\\ns.exe c\\ns2\\bin\\100n-500k-5.tcl"
    for further details on how to use Runtime.exec(), see http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • Monitoring a Process using Runtime.exce()

    Hi,
    In my Program, I'm using the
    new BufferedReader(new InputStreamReader(Runtime.getRuntime()                         .exec("ps -ef | grep xmlfeed").getInputStream()));
    The above statement is not returning any inputstream to the BuffredReader.
    When I gave the command as "PWD", it's returning the lines as expected.
    But it's not working even for "PS" command also.I'm running this in AIX machine.
    Any Ideas,Please help....
    Edited by: haijdp on Dec 21, 2007 1:11 AM

    Hello! And sorry I didn't reply earlier. I hope the Original Poster will find revisit this thread and it helps him.
    From your post I assumed that you were not a student trying to create some homework. That's why I felt free to simply code a solution and submit the code here. But first some remarks:
    I don't think that your code can work. Runtime.exec expects an array of type String, where the first element is the command and subsequent elements are a command line option each. I don't think you can use the pipe and call several commands using Runtime.exec, but that's just a kind of guess. YMMV.
    Running external Processes in Java is a bit complicated. Basically,
    * It's good to run the process in it's own thread. That way the main program can continue without getting stuck.
    * To extract stdout and stderr of your target process you must run two threads, one for stderr and one for stdout. Both threads extract the characters of their respective streams in a loop that runs inside the thread. Again, that way we avoid deadlocks, program getting stuck etc.
    This explanation is terrible, I know - I think a slice of source code speaks louder than words. I have attached five java files which together make a little process runner which extracts stdout and stderr in a safe manner. To run:
    * Cut'n paste them into five text files, one per class.
    * Save the each text file as {contained-class-name}.java
    * Compile the stuff
    * Run RunnerDemo (When I ran it, I got a directory listing printed on the console)
    Explanation sounds a bit sloppy, but I did it under the assumption that you are a seasoned java pro, so it should not pose any problems. Since you seem to be a different OS than I (AIX, I run Linux), the command may or may not work. Try other commands. For example, in the RunnerDemo class you could set the cmd field to this:
            String [] cmd =
                "ps",
                "-A",
                "-H"
            };This would give you a process listing (works on Linux).
    By the way, commands are passed as array. See Java documentation for java.lang.Runtime.exec (String []) for explanation of this array.
    One problem I see in your command is that the output of ps is piped to some other program. Sorry, I don't know whether my code could achieve this. All it can do is to rum one single command with command line options. But you should be able to adjust the given example, so it supports piping to another program.
    If you have any further questions, please don't hesitate to ask!
    Class: RunnerDemo
    *                           RunnerDemo.java
    *                     Demo for the process runner
    package rtimeexec;
    public class RunnerDemo
        public static void main (String [] args)
            String [] cmd =
                "ls",
                "-a",
                "-l"
            ProcessRunner   runner;
            String          stdOutStr;
            String          stdErrStr;
            runner = new ProcessRunner (cmd);
            runner.start ();
            runner.BlockUntilFinished ();
            stdOutStr = runner.GetStdOutText ();
            stdErrStr = runner.GetStdErrText ();
            System.out.println ("Process result, ls -a -l");
            System.out.println ("-----------------------------------------------------------------------");
            System.out.println ("Stdout:");
            System.out.println ("-----------------------------------------------------------------------");
            System.out.println (stdOutStr);
            System.out.println ();
            System.out.println ("-----------------------------------------------------------------------");
            System.out.println ("Stderr:");
            System.out.println ("-----------------------------------------------------------------------");
            System.out.println (stdErrStr);
    Class: ProcessRunner
    package rtimeexec;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    * Runs a system process and extracts stdout and stderr of that process.
    * Process will run in its own thread, so that the caller can simply continue
    * with less of a chance to get locked down. Caller can invoke the {@link BlockUntilFinished}
    * method after starting this thread. This method blocks until the thread is finished,
    * i.e. the process has finished.
    * Unfortunately, we haven't implemented any facility to stream characters to
    * stdin of the process called. If that facility would exist we could refactor
    * the classes and realize some sort of piping facility, as it's possible in
    * Linux, for example.
    * Example on how to run a process:
    * <pre>
    * String []         cmd  = {"ps", "-AH"};
    * String            sOut;
    * String            sErr;
    * ProcessRunner     runner;
    * runner = new ProcessRunner (cmd);
    * runner.start ();
    * runner.BlockUntilFinished ();
    * sOut = runner.GetStdOutText ();
    * sErr = runner.GetStdErrText ();
    * System.out.println ("Stdout:");
    * System.out.println (sOut);
    * System.out.println ("------------------------------------------------------");
    * System.out.println ("Stderr:");
    * System.out.println (sErr);
    * </pre>
    public class ProcessRunner extends Thread
        private String []                   command;
        private int                         execResult;
        private String                      stdOutText;
        private String                      stdErrText;
        private boolean                     isFinished;
        public ProcessRunner (String [] cmd)
            command     = cmd;
            execResult  = 0;
            stdOutText  = null;
            stdErrText  = null;
            isFinished  = false;
        public int GetResult ()
            return execResult;
        public String GetStdOutText ()
            return stdOutText;
        public String GetStdErrText ()
            return stdErrText;
        public boolean IsFinished ()
            return isFinished;
        public void BlockUntilFinished ()
            while (! isFinished)
                try {Thread.sleep (250);} catch (InterruptedException e) {}
        public void run ()
            Process         proc;
            Runtime         rt;
            InputStream     stdOut;
            InputStream     stdErr;
            CharStream      stdOutEx;
            CharStream      stdErrEx;
            int             res;
            isFinished = false;
            try
                res         = 0;
                rt          = Runtime.getRuntime ;       ();
                proc        = rt.exec ;                  (command);
                stdOut      = proc.getInputStream ;      ();
                stdErr      = proc.getErrorStream ;      ();
                stdOutEx    = new CharStream            (stdOut);
                stdErrEx    = new CharStream            (stdErr);
                stdOutEx.start ();
                stdErrEx.start ();
                try {res = proc.waitFor ();} catch (InterruptedException e) {}
                // Process has finished; now wait until any buffers are empty.
                stdOutEx.BlockUntilFinished ();
                stdErrEx.BlockUntilFinished ();
                stdOutText = stdOutEx.GetResult ();
                stdErrText = stdErrEx.GetResult ();
                execResult = res;
            catch (IOException e)
                isFinished = true;
                throw new ExtractionException (e.getLocalizedMessage());
            isFinished = true;
    Class: CharStream
    package rtimeexec;
    import java.io.IOException;
    import java.io.InputStream;
    * A Character extractor. Extracts characters from a stream and puts them
    * into a String. To protect from memory overflow we put a limit in place.
    * When storage demads exceed that limit, an exception is thrown.
    public class CharStream extends Thread
        private static final int    maxChunkLen         = 8192;
        private static final int    maxStorageSize      = 512 * 1024;   // 512 KBytes
        private InputStream     sourceStream;
        private StringBuffer    extracted;
        private boolean         isFinished;
        public CharStream (InputStream istream)
            sourceStream    = istream;
            extracted       = new StringBuffer ();
            isFinished      = false;
        public String GetResult ()
            String ret;
            ret = extracted.toString ();
            return ret;
        public void BlockUntilFinished ()
            while (! isFinished)
                SleepThread (250);
        public void run ()
            byte []                 buffer;
            int                     nBytesRead;
            byte                    b;
            char                    c;
            int                     iChar;
            int                     nCharsTotal;
            boolean                 isEOF;
            isEOF       = false;
            nCharsTotal = 0;
            isFinished = false;
            while (! isEOF)
                try
                    buffer      = new byte [maxChunkLen];
                    nBytesRead  = sourceStream.read (buffer);
                    if (nBytesRead >= 1)
                    {   // much faster stream extraction method than when we use
                        // BufferedReader(new InputStreamReader(sourceStream)).
                        for (iChar = 0; iChar < nBytesRead; iChar++)
                            nCharsTotal++;
                            if (nCharsTotal > maxStorageSize)
                                throw new StoreFullException
                                    "Storage limit exceeded (" + Integer.toString (maxChunkLen) + "Bytes)"
                            b = buffer [iChar];
                            c = (char) b;
                            extracted.append (c);
                    else if (nBytesRead <= -1)
                        isEOF       = true;
                catch (IOException e)
                    isFinished = true;
                    throw new ExtractionException (e.getLocalizedMessage());
                SleepThread (250);
            isFinished  = true;
        private void SleepThread (int mSec)
            try
                Thread.sleep (mSec);
            catch (InterruptedException e)
    Class: StoreFullException
    package rtimeexec;
    * Exception that gets thrown when a storage container is full.
    public class StoreFullException extends RuntimeException
        private static final long serialVersionUID = - 4996246591135389009L;
        public StoreFullException (String message)
            super (message);
    Class: ExtractionException
    package rtimeexec;
    * Thrown when there was some problem during stream extraction.
    public class ExtractionException extends RuntimeException
        private static final long serialVersionUID = - 6124525536783450209L;
        public ExtractionException (String message)
            super (message);
    }

  • Parameter  to shell script using Runtime.exec(string)

    Hi all, ( Speciall hi to dheeraj tak )
    Briefly : How do i pass an arguement to a non - java executible being called using Runtime.exec.
    In detail : i am using Runtime.exec to call a shell script : The code is as follows:
    String callAndArgs[] = {"/home/tom/jakarta-tomcat-4.1.24/webapps/dash/script.sh"};
    try {
    Runtime rt = Runtime.getRuntime();
    Process child = rt.exec(callAndArgs);
    This works properly & calls the shell script which in turn invokes some other executible (c file).
    $HOME/midi/test/build/bin/<C-EXECUTIBLE>
    Here i am specifying the name (say hello.exe ) . So far so good.
    I want to make this happen dynamiclaly. so i need to pass the name of the executible as a parameter to the script.
    To pass a parameter i hav to change the string to :-
    String callAndArgs[] = {"/home/tom/jakarta-tomcat-4.1.24/webapps/dash/script.sh <C-EXECUTIBLE HERE>"};
    and the script to
    $HOME/midi/test/build/bin/$1 --- where $1 refers to argument 1. (C-EXECUTIBLE AGAIN).
    This is giving an IO - Execption. Plz help
    Code will be very helpful.
    Thanx in advance

    some 1 plz tell me the difference :-
    This is the documentation of Runtime.exec that i found :-
    1> exec
    public Process exec(String command) throws IOException
    Executes the specified string command in a separate process.
    The command argument is parsed into tokens and then executed as a command in a separate process. This method has exactly the same effect as exec(command, null).
    Parameters:
    command - a specified system command
    Complete refernce says : Process (String progName) ----- Executes a program specified by programname as a seperate process.
    2> exec
    public Process exec(String cmdarray[]) throws IOException
    Executes the specified command and arguments in a separate process.
    The command specified by the tokens in cmdarray is executed as a command in a separate process. This has exactly the same effect as exec(cmdarray, null).
    Parameters:
    cmdarray - array containing the command to call and its arguments.
    Complete reference says : Process exec(String comLineArray[]) ---- Executes the command line specified bythe string in comLineArray as a seperate process.
    This means that there is provision 4 command line arguments...
    how do u use it then????????????????????????????

  • Can we run a java application using Runtime.exec()?

    Can we run a java application using Runtime.exec()?
    If yes what should i use "java" or "javaw", and which way?
    r.exec("java","xyz.class");

    The best way to run the java application would be to dynamiically load it within the same JVM. Look thru the class "ClassLoader" and the "Class", "Method" etc...clases.
    The problem with exec is that it starts another JVM and moreover you dont have the interface where you can throw the Output directly.(indirectly it can be done by openong InputStreams bala blah............). I found this convenient. I am attaching part of my code for easy refernce.
    HIH
    ClassLoader cl = null;
    Class c = null;
    Class cArr[] ;
    Method md = null;
    Object mArr[];
    cl = ClassLoader.getSystemClassLoader();
    try{
         c = cl.loadClass(progName.substring(0,progName.indexOf(".class")) );
    } catch(ClassNotFoundException e) {
    System.out.println(e);
         cArr = new Class[1] ;
         try{
         cArr[0] = Class.forName("java.lang.Object");
         } catch(ClassNotFoundException e) {
         System.out.println(e);
         mArr = new Object[1];
         try{
         md = c.getMethod("processPkt", cArr);
         } catch(NoSuchMethodException e) {
         System.out.println(e);
         } catch(SecurityException e) {
         System.out.println(e);
    try {            
    processedPkt = md.invoke( null, mArr) ;
    } catch(IllegalAccessException e) {
              System.out.println(e);
    } catch(IllegalArgumentException e) {
              System.out.println(e);
    }catch(InvocationTargetException e) {
              System.out.println(e);
    }catch(NullPointerException e) {
              System.out.println(e);
    }catch(ExceptionInInitializerError e) {
              System.out.println(e);
    }

  • Using Runtime to call a number of commands in one session

    Hi,
    I've got a windows BAT file which sets up the Windows environment variables needed to run a command line program. When using this manually I just have a shortcut which calls "cmd /k c:\blah\mybat.bat" and opens a command line windows I can use to work in. How can I do the equivalent from within my Java code?
    I understand that I can use Runtime as follows:
    Process pr = rt.exec("cmd \"C:\\Program Files\\FWTools2.4.4\\setfw.bat\"");
    BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));
    String line=null;
    while((line=input.readLine()) != null) {
         System.out.println(line);
    }But I also need to run a command line program from within the same session (otherwise it won't work, as the environment variables are not set). The other command I need to call is:
    Process  pr = rt.exec("gdal_merge -o " + outTif + " -separate " + inTif);How can I call both of these in one command line session?
    I hope that makes sense :S
    Thanks,
    Jon
    Edited by: DeadPassive on Oct 7, 2009 7:11 AM

    Use Runtime.exec() to invoke cmd.exe and then write the sequence of commands to the process stdin. You should handle both stdout and stderr in separate threads. If you have not done so already, you should read the 4 sections of [http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html|http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html] and you should implement the recommendations.

  • Using Runtime.exec to execute Java.exe

    I am trying to use Runtime.exec to spawn a thread that runs java.exe, but havn't had any luck. I have two versions of code, the first one works (example 1), but I want to eliminate the use of "cmd /c" to keep system independance. The second example (example 2) does not work. Both versions work if invoked from the command line. I'm running Win2000. Any Ideas?
    Example 1:
    aProcess = aRuntime.exec("cmd /c java.exe
    -cp "<MyClassPathHere>" <arg1> <arg2> <arg3> <arg4> <arg5>");
    Example 2:
    aProcess = aRuntime.exec("java.exe
    -cp "MyClassPathHere" <arg1> <arg2> <arg3> <arg4> <arg5>");

    I think you mix two concepts: "threads" and "processes". A "thread" is a thread of execution inside the VM, but you want to actually start a new VM in a new process, which is an OS level thing, right?
    I've tried Idea 2 also, same result: works if
    i specify cmd c/, doesn't if I don't.It should work if java.exe is in your path... are you taking care of the standard streams of your process?

  • Launching another Swing application from existing one using Runtime.exec()

    Hi,
    I have two separate Swing applications, say A and B. I need to launch B from A using Runtime.exec() - essentially I am launching another VM instance from one VM. I am encountering strange problems - B's main window comes up, but GUI doesn't update; sometimes B comes up and GUI updates, but huge memory leaks happen. All the problems with B go away once A is shut down. It almost looks like both the instances of VM are sharing (or competing for) the event thread. Any comments will be of great help. Thanks.
    note: There is no problem launching B if A is a console java application (i.e. no Swing GUI).

    Do you have to have the second application running in a seperate VM (process)? If not completely neccesary, then you can just invoke the static main() of the second class. If the type of the second class isn't known untill run-time, you can use Reflection to invoke the method.
    Miguel

  • Executing a command using Runtime Class

    How to execute a command on a differnet machine with different ipaddress using Runtime Class
    My code is
    String[] cmd = new String[3];
    cmd[0] = "192.1...../c:/WINNT/system32/cmd.exe" ;
    cmd[1] = "/C" ;
    cmd[2] = args[0];
    Runtime rt = Runtime.getRuntime();
    System.out.println("Execing " + cmd[0] + " " + cmd[1]
    + " " + cmd[2]);
    Process proc = rt.exec(cmd);
    // any error???
    int exitVal = proc.waitFor();
    System.out.println("ExitValue: " + exitVal);
    This is not Working

    I have same issue. Actually when I use cmd.exe /c set in java code and if I run the java code in DOS propmt, it retrieves all latest user Environment variable values. But if I run the code in windows batch file, it is not retrieveing the latest user environment values until I reboot my computer, Do you know how to get user environment value with out rebooting machine??????

  • FTP using Runtime class ...Please Help ??

    Hi,
    I am trying to ftp a file programatically.
    I am trying to use Runtime class but facing problems
    in it.This is what I am trying to do :
    Runtime rr = Runtime.getRuntime();
    String[] cmds = new String[2];
    cmds[0]="username=rahmed";
    cmds[1]="password=prpas";
    try{
    Process p = rr.exec("ftp 192.168.1.18",cmds);     
    rr.exec("put vv.txt");
    This does not work ??
    Is there any way to make it work ? Or is there any
    other way to ftp a file programatically ??
    Thanks in adavance..
    Regards
    Rais

    Under Linux/Unix at least, it is good to use the switches -n and -i with the ftp client acually meant for intercative usage.
    -i Turns off interactive prompting during multiple file transfers.
    -n Restrains ftp from attempting ``auto-login'' upon initial connection.
    I do "user <myuser> <mypassword>" then from the script.
    I am happily using ftp this way from shell-scripts in my projects.
    scp is however better than ftp: it does not send plain text passwords over the net, it support key-based login, its encrypts the data.

  • Issue regarding creating a process using Runtime in Windows 2003.

    Hi all..
    I need to resolve a small issue related to execute an external program using runtime execution method. But when i deploy the code in websphere application server 6.1V in windows 2003 server operating system, it is starting a process with min priority and not executing even i specified waitfor method.
    The code is like below.
    try{
    Process p = Runtime.getRuntime().exec("C:\\CopyImages.exe "+toWrite);
    int ep = p.waitFor();
    System.out.println("process "+ep);
    catch(Exception e)
    e.printStackTrace();
    Please help me in resolving this issue. The above code is working in my IDE which is in Window XP but when i port it in application server in windows2003 i'm getting this issue.

    hi..
    it is a typo error. i've given the slashes with that.
    but still getting the problem.

  • Using Runtime exec() method to run java files and return runtime errors

    Hi
    I'm writing a java editor and I use
    Runtime.getRuntime().exec(command)
    to compile the java files. That works fine and I deal with the returned errors using the getErrorStream().
    My questions are:
    1. Can I use the same technique for returning runtime errors. In any posts I've read the process runs from begining to end, returning the errors after completion. How do I return the errors of the app as they happen interactively?
    2. If i cant use the exec and getErrorStream() methods then does anyone know how it is done?
    Thanks in advance for any help!

    Read this:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    MOD

  • 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 use Runtime.getRuntime().exec() in JSP? is it works in JSP or not

    Hi to all,
    i want run a .exe file from JSP file. In java i am able do this, using Runtime.getRuntime().exec().
    but same thing, when i trying with JSP it is not working?
    plz let me is there any other ways to do it..

    It depends, usually (ie in an J2EE container) you're not allowed to access files or the runtime environment, by definition. What do you wan't to achieve with the exe?
    --olaf                                                                                                                                                                                                                                                                                                                                                           

  • Spawn a java process using runtime.exec() method

    Hi,
    This is my first post in this forum. I have a small problem. I am trying to spawn a java process using Runtime.getRuntime().exec() method in Solaris. However, there is no result in this check the follwoing program.
    /* Program Starts here */
    import java.io.*;
    public class Test {
    public static void main(String args[]) {
    String cmd[] = {"java", "-version"};
    Runtime runtime = Runtime.getRuntime();
    try{
    Process proc = runtime.exec(cmd);
    }catch(Exception ioException){
    ioException.printStackTrace();
    /* Program ends here */
    There is neither any exception nor any result.
    The result I am expecting is it should print the following:
    java version "1.4.0"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
    Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
    Please help me out in this regard
    Thanks in advance
    Chotu.

    Yes your right. It is proc.getInputStream() or proc.getErrorStream(). That is what I get for trying to use my memory instead of looking it up. Though hopefully the OP would have seen the return type of the other methods and figured it out.

Maybe you are looking for