Help me ! about Runtime.exec()

[php]
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.File;
     /** * Class for running external executable (extrnal process).*/
public class ExeRunner{     
/* Path to Dlls required by the executable */
String path = "C:\\Program Files\\jdk1.4\\bin";
public void run(String [] args) throws IOException, InterruptedException
final Process p = Runtime.getRuntime().exec(args, new String [] {path});
new Thread()
public void run()
try
BufferedReader in = new BufferedReader (new InputStreamReader (p.getInputStream()));     
String str = null;     
while ((str = in.readLine()) != null )     
System.out.println(str);     
in.close();     
catch (IOException e){      
e.printStackTrace();     
}.start();
new Thread()
public void run()
try     {     
BufferedReader in      = new BufferedReader (new InputStreamReader (p.getErrorStream()));     
String str = null;     
while ( (str = in.readLine()) != null )
System.err.println(str);
in.close();     
catch (IOException e)
{       e.printStackTrace();
}.start();
int exitCode = p.waitFor();          
if ( exitCode != 0 )
throw new IOException ("Executable "+args[0]+" stopped with error code "+exitCode);
public static void main(String [] a) throws Exception
String args [] = new String[4];
args[0] = "C:\\Program Files\\jdk1.4\\bin\\java.exe";
args[1] = "-classpath";
args[2] ="E:\\Practical";
args[3] ="HelloWorld";
new ExeRunner().run(args);
[php]

I get the above from another forum. the program running well.
however , my problem is that I want to it display another DOS console to print the "Hello World ".
and the DOS console will not closed untill user close it.
/* Path to Dlls required by the executable */
String path = "C:\\Program Files\\jdk1.4\\bin";
final Process p = Runtime.getRuntime().exec(args, new String [] {path});
can you explain what the above line doing. and what is the "path" means?
I also tried to change the codes in main method
String args [] = new String[6];
args[0] ="cmd.exe";
args[1] ="/start";
args[2] = "C:\\Program Files\\jdk1.4\\bin\\java.exe";
args[3] = "-classpath";
args[4] ="E:\\Practical";
args[5] ="HelloWorld";
new ExeRunner().run(args);
But it does not work.
Thanks very much!

Similar Messages

  • Question about Runtime.exec

    Rob,
    Thanks for your help.
    I asked a question about a weird Exception on Nov 14, and you told me that I am
    using Runtime.exec to start an external process, and that process is crashing.
    I am a green-hand on Weblogic, and I am trying to enhancing a project developped
    by another person, so I am not familiar with some concepts yet.
    Could you please give me some simple explanation about Runtime.exec and external
    process?
    I found two methods that uses "Runtime" from two classes as following, could you
    help me to see whether or not there is something wrong with the usage of Runtime?
    Thank you very much.
    private int runShellCommand(String command) {
    int exitVal = -1;
    try {
    File runDir = new File(runDirectory);
    String[] env = new String[0];
    Runtime rt = Runtime.getRuntime();
                   double start = System.currentTimeMillis();
    Process proc = rt.exec(command, env, runDir);
    // Capture output in separate thread
    ThreadedStreamReader error = new ThreadedStreamReader(proc.getErrorStream(),
    "ERROR");
    ThreadedStreamReader output = new ThreadedStreamReader(proc.getInputStream(),
    "OUTPUT");
    error.start();
    output.start();
    exitVal = proc.waitFor();
    if (logger.isDebugEnabled()) {
         double runtime = (System.currentTimeMillis() - start) / 1000.0;
         logger.info("run " + runId + " " + command + " finished in " + runtime
    + " seconds");
    } catch (IOException e) {
    logger.fatal("DOE-2 failed \n" + e.getMessage());
    } catch (InterruptedException e) {
    e.printStackTrace();
    return exitVal;
    public static void main(String[] args) throws Exception, InterruptedException
    final Doe2MessageServer server = new Doe2MessageServer();
    while(!connected) {
    Thread.sleep(1000);
    logger.info("Attempting to start JMS service ...");
                   try {
              server.init();
                   } catch (Exception ex) {
    // shutdown hook to close JMS connection
    Runtime.getRuntime().addShutdownHook(
    new Thread() {
    public void run() {
    server.finalize();
    server.receiveMessage();

    Runtime.exec is a J2SE API. It's not really specific to WLS.
    You can read about it here:
    http://java.sun.com/j2se/1.4.1/docs/api/java/lang/Runtime.html
    It looks like you are starting a JMS Server in a separate process and
    that process is crashing.
    (You could of course just use WLS's JMS Server instead :>)
    -- Rob
    Iris Qu wrote:
    Rob,
    Thanks for your help.
    I asked a question about a weird Exception on Nov 14, and you told me that I am
    using Runtime.exec to start an external process, and that process is crashing.
    I am a green-hand on Weblogic, and I am trying to enhancing a project developped
    by another person, so I am not familiar with some concepts yet.
    Could you please give me some simple explanation about Runtime.exec and external
    process?
    I found two methods that uses "Runtime" from two classes as following, could you
    help me to see whether or not there is something wrong with the usage of Runtime?
    Thank you very much.
    private int runShellCommand(String command) {
    int exitVal = -1;
    try {
    File runDir = new File(runDirectory);
    String[] env = new String[0];
    Runtime rt = Runtime.getRuntime();
                   double start = System.currentTimeMillis();
    Process proc = rt.exec(command, env, runDir);
    // Capture output in separate thread
    ThreadedStreamReader error = new ThreadedStreamReader(proc.getErrorStream(),
    "ERROR");
    ThreadedStreamReader output = new ThreadedStreamReader(proc.getInputStream(),
    "OUTPUT");
    error.start();
    output.start();
    exitVal = proc.waitFor();
    if (logger.isDebugEnabled()) {
         double runtime = (System.currentTimeMillis() - start) / 1000.0;
         logger.info("run " + runId + " " + command + " finished in " + runtime
    + " seconds");
    } catch (IOException e) {
    logger.fatal("DOE-2 failed \n" + e.getMessage());
    } catch (InterruptedException e) {
    e.printStackTrace();
    return exitVal;
    public static void main(String[] args) throws Exception, InterruptedException
    final Doe2MessageServer server = new Doe2MessageServer();
    while(!connected) {
    Thread.sleep(1000);
    logger.info("Attempting to start JMS service ...");
                   try {
              server.init();
                   } catch (Exception ex) {
    // shutdown hook to close JMS connection
    Runtime.getRuntime().addShutdownHook(
    new Thread() {
    public void run() {
    server.finalize();
    server.receiveMessage();

  • Very very urgent! Please help about Runtime.exec on Solaris

    I wrote a software in Java.
    It contains a platform application and a variety of client applicaitons.
    Both use Swing MMI. I need my own JRE and invoke client from
    platform MMI. On Windows, the software run ok. But on Solaris,
    client are always blocked to do work.
    Whe run platform and client individually from command line,
    client will run ok too. While client is invoked by platform in programm,
    it will be blocked to run (client cannot recieve data from RS232).
    I noticed that client will continue to run once platform exits.
    So I really wonder whether there is something wrong with my codes
    to invoke client. Only Solaris invoking codes list here.
      public static boolean exec(String execStr) {
        Runtime runtime = Runtime.getRuntime();
        try {
          String[] args  = new String[] {
                "/bin/sh", "-c", execStr};
            Process p = runtime.exec(args);
            return true;
          return false;
         catch (Exception e) {
          e.printStackTrace();
        return false;
      }

    The execStr argment is
    /users/devConfig/jre/java -classpath "/users/devConfig/jre/lib:/users/devConfig/lib/ssop.jar:
    /users/devConfig/lib/zt103.jar..." zt.client.nsd200v.NSD200VApp ...Where /users/devConfig is my software installed directory, and /users/devConfig/jre is my own packaged JRE1.5.0.

  • Need info about Runtime.exec

    Hello, I have a non program specific question about how Runtime.exec works. First off assume that I handle all my input streams and output streams correctly, and I am not worried about inter process communication. The question is, when I use Runtime.getRuntime().exec(cmd[],pth[],dir) does the JVM that is running the code that calls it live until the spawned process dies, or can it die without waiting for the execed process to die? I am trying to write an app that can spawn a new copy of itself that is completely independent from the original process, and may live on long after the original is no longer needed. To ensure proper resource management I need to know that the JVM that launches the new process does not have to wait for the new process to die prior to completely cleaning itself up.
    Does that make sense?
    Any suggestions, ideas, questions?
    Thanks in advance for the help.
    Message was edited by:
    elixic

    Thank you all who gave useful input. I had done some reading on this already and could not find a definite answer on weather or not the calling JVM can properly dispose of itself prior to the process it called being disposed of.
    The answer it seems is dependent on context. In windows, and from a GUI app, it looks like the calling JVM can die any time it wants too. A command line app on the other hand seems to have to wait for the app it called to die first. I have not tested it on other OS's but I am sure it varies by OS as well. I would not even be surprised if it varies by JVM.
    So the short answer to my question that you all helped me find is this, It varies by context.
    Thanks again for the help.
    Isaac

  • Urgent Help Required : Java Runtime.exec

    Hello,
    We are using the java Runtime.exec in the AIX 4.3.3 environment. Java version 1.1.8. We are consuming the output of the Runtime.exec without using the threads. i.e we are doing a readline on the output stream of the runtime and printing it to th standard output in a loop. When this is over we take the error stream and do the same.
    We have two problems.
    1. A ksh that is run using the java Runtime.exec is showing up multiple processes with the same as a tree structurre when we do a ps.
    Why is this ?
    2. Also whatever we consume from the standard output/error of runtime and print it to system.out is not being output/error. Any pointers on this ?
    Thanks in advance,
    Raj.

    thanks !
    1. we have single thread executing the command. And there are no multiple processes spawned inside the shell script also.
    2. I am sorry about the phrasing. Eventhough we are catching the output stream and error stream and dumping the output correspondingly, the process ( the shell script ) hangs ! And this behaviour is sporadic. Please let us know why the process should hang !
    Thanks,
    rajesh.

  • Pls help me about Runtime.getRuntime().exec("java...")

    I have two applications. One is Client, the other is Platform.
    In the Platform, there are source files packaged into a library named ZtConfig.jar used by Client. If run Client and Platform, two applications can execute normally.
    But if Client is started by user from platform, there is something wrong.
    I noticed the error difficultly with finally catching exception.
    I was puzzled. It is so strange. Pls help me. I list some codes here.
    In Client where finally exception catched:
    import zt.config;
            try {
              xmlFileUrl = new java.net.URL(
                  "file:///e:/Client/src/config/nsr1000.xml");
            catch (IOException ex1) {
              FileLogger.error(ex1.getMessage());
            FileLogger.info("NSR1000Document.setIEDContent", xmlFileUrl.toString());
            try {
              xmlLoader = new XMLConfigLoader(xmlFileUrl);
            finally {
              FileLogger.error("NSR1000Document.setIEDContent",
                               "cannot new XMLConfigLoader object");
              return; // the following codes cannot execute, so have to return here.
    In the XMLConfigLoader, the constructor is
      public XMLConfigLoader(java.net.URL xmlFileUrl) {
        this.xmlFileUrl = xmlFileUrl;
        configDoc = null;
        builder = null;
        xmlDoc = null;
    Platform start Client application using the following code
      Runtime.getRuntime().exec(
                    "java -jar e:/Client/Client.jar");

    I've got it!
    Briefly, it is because classpath setting was overwritten by JBuilder.
    Firstly, I start Platform from JBuilder. In its messages window. The command is
    d:\j2sdk1.4.2_06\bin\javaw -classpath "JBPATH" zt.client.nsr1000.NSR1000App
    Now, classpath environment variable was changed to be JBPATH. While I start
    Client use Runtime.getRuntime().exec("java -jar Client.jar"), it will not run for classpath changed.
    Then, I configured all packages used by Client into JBuilder libraries, including
    Client.jar. And changed codes Runtime.getRuntime().exec("java -jar Client.jar") to be Runtime.getRuntime().exec("java -Xmx128m zt.client.nsr1000.NSR1000App")
    I also changed CLASSPATH windows system environment variable.
    I found this from command console, it can display exceptions. But from JBuilder, there is no exception that can be captured. So debug is difficult.

  • How to make this works. it's about Runtime.exec().

    hi' i really need help about this.
    i have 2 class file. one named GoodWindowsExec that used to execute another file named maintest. (i post my code below). When i run GoodWindowsExec there's no problem but not working correctly.
    What i need is i can write something directly from my keyboard not via GoodWindowsExec file. So maintest can run normally just like when i execute it manual (java maintest from commandprompt) and display the output. If you look at the maintest file, this file need input from user. But why i can't doing this directly? How to implement this?
    This is java code that i need to execute (maintest) just for sample :
    public class maintest
         public static void main(String[] args)
              try
                   BufferedReader bfr = new BufferedReader(new InputStreamReader(System.in));
                   System.out.print("Try input word : ");
                   String readInput = bfr.readLine();
                   /* String readInput = bfr.readLine(); i think this is the problem.
                    * If i remove this, GoodWindowsExec works fine.
                    * But i cannot remove it. This is my point.
                    * i want try to solve this */
                   System.out.println(readInput);
              catch(Exception e)
                   System.out.println(e);
    }This is my code (GoodWindowsExec) which used to execute maintest :
    public class GoodWindowsExec
         public GoodWindowsExec()
              try
                   String[] cmd = new String[]{"cmd.exe","/C","java","maintest"};
                Runtime rt = Runtime.getRuntime();
                   Process proc = rt.exec(cmd);
                   InputStream inStream = proc.getInputStream();
                   BufferedReader bfr = new BufferedReader(new InputStreamReader(inStream));
                   response res_in = new response(bfr);
                   InputStream errorStream = proc.getErrorStream();
                   BufferedReader errorBfr = new BufferedReader(new InputStreamReader(errorStream));
                   response res_err = new response(errorBfr);
                   res_in.start();
                   res_err.start();
                   OutputStream otStream = proc.getOutputStream();
                   DataOutputStream write = new DataOutputStream(otStream);
                   write.writeUTF("something");
                   /* write.writeUTF("something");
                    * i really don't know about this.
                    * if i declare this, the input not come from maintest / user directly.
                    * if i create some java editor application and want to execute some java code
                    * this is not right. cos input comes from this class not the execute class (maintest).
                    * How to make the input comes from user / execute class?
                   write.flush();
                   write.close();
                int exitVal = proc.waitFor();
                System.out.println("ExitValue: " + exitVal);       
              catch (Throwable t)
                 t.printStackTrace();
        public static void main(String args[])
              new GoodWindowsExec();
    class response extends Thread
         BufferedReader bfr;
         public response(BufferedReader bfr)
              this.bfr = bfr;
         public void run()
              try
                   String line = null;
                   while ( (line = bfr.readLine()) != null)
                             System.out.println(line);   
              catch (IOException ioe)
               ioe.printStackTrace(); 
    }Thank you very much...

    Hi' i think i have same problems with you. but now i think i got it after read this article. Thanks for both of you. specially sabre150.
    But i want to ask about this to sabre150. What if maintest try to request more than one input? How to handle it? and why Try input word : display at the second line? not the first line?
    i'm sorry if i modify this, but i change it like this :
    class outputer :
    public void run()
         try
              bfr = new BufferedReader(new InputStreamReader(System.in));
              String input = null;
              while ((input = bfr.readLine()) != null)
                   write.writeBytes(input);     
                   write.flush();
                   write.close();
         catch(Exception e)
              e.printStackTrace();
    }maintest :
    public class maintest
         public static void main(String[] args)
              try
                   BufferedReader bfr = new BufferedReader(new InputStreamReader(System.in));
                   System.out.print("Try input word : ");
                   String readInput = bfr.readLine();
                   System.out.println(readInput);
                   System.out.print("Try input word again : ");
                   String readInput2 = bfr.readLine();
                   System.out.println(readInput2);
              catch(Exception e)
                   System.out.println(e);
    }When i execute i got this :
    test //request for first input
    Try input word : test
    Try input word again : null
    ExitValue: 0
    halo //request for second input
    java.io.IOException: The handle is invalid
         at java.io.FileOutputStream.writeBytes(Native Method)
         at java.io.FileOutputStream.write(Unknown Source)
         at java.io.BufferedOutputStream.flushBuffer(Unknown Source)
         at java.io.BufferedOutputStream.flush(Unknown Source)
         at java.io.DataOutputStream.flush(Unknown Source)
         at outputer.run(GoodWindowsExec.java:78)Maybe you know the answer sabre150?
    Thanks...
    Message was edited by:
    2Puluh11Lapan3

  • About runtime.exec("passwd")

    In solaris,you can use command "passwd" to change password of user.
    Now i want to use the command in java.But i can not get the result like below:
    %new password:(type the password)
    Re-type password:
    my codes is copied here,please help me .
    import java.util.Enumeration;
    import java.io.*;
    import java.lang.*;
    public class liu{
         public static void main(String args[]) throws Exception{
              try{
                   Runtime rr=Runtime.getRuntime();
                   String[] aaa={ "passwd"};//passwd liuyang"};//ls -l"};
                   Process cess=rr.exec(aaa);
              String sss;
                   DataOutputStream out=new DataOutputStream(new BufferedOutputStream(cess.getOutputStream()));
    //               out.writeBytes("qwerty\n");
                   out.writeBytes("OUTPUT");
                   out.flush();
                   DataInputStream in=new DataInputStream(cess.getInputStream());
                   while((sss=in.readLine())!=null)
                        System.out.println(sss);
              }catch (Exception ex) {
                   System.out.println("Exception:"+ex);

    I would really recommend not to code your own password utility in java. Yours will be insecure and will echo onto the screen whilst the default unix one will be as secure as sun can make it.
    Jon

  • About runtime.exec()

    hi friends,
    i'm unable to open vb exe file through java application.
    i'm tring with this code
    Process p = Runtime.getRuntime().exec("cmd /D:Program Files/Microsoft Visual Studio/VB98/socketappvb/");
    p.waitfor()
    that is the error in my code.
    thank is advance

    Your exec string doesn't look right. What the heck are those forward slashes? And why do you call cmd for an exe? (Can't say for sure, but I believe the cmd is only required to execute batch files.)

  • HELP needed for Runtime.exec

    Here is the code. I'm able to compile it but the code doesn't FTP the file.
    String xfer = "g:/java/code/xfer.txt";
    String xferout="g:/java/code/xferout.txt";
    String[] ftpCommand={"ftp"," -n"," -s:" + xfer + " >" + xferout};
    Process processOutput = null;
    //String homeDir="c:/java";
    //File xferScript=new File(homeDir,xfer);
    PrintWriter xferScript=new PrintWriter(
    new BufferedWriter(
    new FileWriter(xfer)));
    xferScript.println("open " + downloadServer);
    xferScript.println("user " + loginId + " " + password);
    //xferScript.println("lcd " + homeDir);
    xferScript.println("prompt");
    xferScript.println("ascii");
    xferScript.println(method_mget + " " + FileToDownload);
    xferScript.println("dir");
    xferScript.println("bye");
    xferScript.flush();
    xferScript.close();
    Runtime process = Runtime.getRuntime();
    processOutput = process.exec(ftpCommand);

    This should fix it:     String xfer = "g:/java/code/xfer.txt";
         String xferout="g:/java/code/xferout.txt";
         String[] ftpCommand={"ftp"," -n"," -s:" + xfer);
         Process processOutput = null;
         PrintWriter xferScript=new PrintWriter(
              new BufferedWriter(
              new FileWriter(xfer)));
         xferScript.println("open " + downloadServer);
         xferScript.println(loginId);
         xferScript.println(password);          
         xferScript.println("prompt");
         xferScript.println("ascii");
         xferScript.println(method_mget + " " + FileToDownload+" "+xferout);
         xferScript.println("dir");
         xferScript.println("bye");
         xferScript.flush();
         xferScript.close();
         try {
              Runtime process = Runtime.getRuntime();
              processOutput = process.exec(ftpCommand);      
         catch (IOException ioe) {
              System.out.println("I/O error has occurred");
         ioe.printStackTrace();
         }Mark

  • 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

  • Need help with Runtime.exec()

    I need help getting my program to run a different java program through the command prompt using the runtime.exec() method. This is my code so far:
    import javax.swing.JOptionPane;
    import javax.swing.JDialog;
    import javax.swing.JButton;
    import javax.swing.JRadioButton;
    import javax.swing.ButtonGroup;
    import javax.swing.JLabel;
    import javax.swing.ImageIcon;
    import javax.swing.BoxLayout;
    import javax.swing.Box;
    import javax.swing.BorderFactory;
    import javax.swing.border.Border;
    import javax.swing.JTabbedPane;
    import javax.swing.JPanel;
    import javax.swing.JFrame;
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.*;
    //import java.Original.*;
    //import java.Turtle.*;
    //import jav.Turtle.galapagos.*;
    public class JavaMenu extends JPanel
         JFrame frame;
         JLabel label;
         JButton select;
         String labDescription = "Java labs created in class.";
         String turtleDescription = "Turtle labs created in class";
         String creationDescription = "Java programs created on my own.";
         public JavaMenu(JFrame frame)
              super(new BorderLayout());
              JPanel lab = labDialog();
              //JPanel turtle = turtleDialog();
              //JPanel creation = creationDialog();
              label = new JLabel("Click Select Program to run the program.", JLabel.CENTER);
              this.frame = frame;
              Border padding = BorderFactory.createEmptyBorder(20,20,5,20);
              lab.setBorder(padding);
              //turtle.setBorder(padding);
              //creation.setBorder(padding);
              JTabbedPane tab = new JTabbedPane();
              tab.addTab("Java Labs", null, lab, labDescription);
              //tab.addTab("Turtle Labs", null, turtle, turtleDescription);
              //tab.addTab("Java Programs", null, creation, creationDescription);
              add(tab, BorderLayout.CENTER);
              add(label, BorderLayout.PAGE_END);
              label.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
         void setLabel(String newText)
              label.setText(newText);
         protected static ImageIcon createImageIcon(String path)
            java.net.URL imgURL = JavaMenu.class.getResource(path);
            if (imgURL != null) {
                return new ImageIcon(imgURL);
            } else {
                System.err.println("Couldn't find file: " + path);
                return null;
         private JPanel labDialog()
              final int numButtons = 25;
              JRadioButton[] javalabs = new JRadioButton[numButtons];
              final ButtonGroup group = new ButtonGroup();
              select = null;
              final String messageCommand2 = "Lab 02";
              final String messageCommand3 = "Lab 03";
              final String messageCommand4 = "Lab 04";
              final String messageCommand41 = "Lab 04 Extra Credit 1";
              final String messageCommand42 = "Lab 04 Extra Credit 2";
              final String messageCommand5 = "Lab 05";
              final String messageCommand51 = "Lab 05 Extra Credit";
              final String messageCommand6 = "Lab 06";
              final String messageCommand6b = "Lab 06";
              final String messageCommand7 = "Lab 07";
              final String messageCommand71 = "Lab 07 Extra Credit";
              final String messageCommand8 = "Lab 08";
              final String messageCommand8b = "Lab 08";
              final String messageCommand81 = "Lab 08 Extra Credit";
              final String messageCommand9 = "Lab 09";
              final String messageCommand9b = "Lab 09";
              final String messageCommand91 = "Lab 09 Extra Credit 1";
              final String messageCommand92 = "Lab 09 Extra Credit 2";
              final String messageCommand93 = "Lab 09 Extra Credit 3";
              final String messageCommand9a = "Lab 09 American Flag";
              final String messageCommand9t = "Lab 09 Texas Flag";
              final String messageCommand0 = "Lab 10";
              final String messageCommand0b = "Lab 10 Hi Lo Game";
              final String messageCommand01 = "Lab 10 Extra Credit 1";
              final String messageCommand02 = "Lab 10 Extra Credit 2";
              javalabs[0] = new JRadioButton("Lab 02 100 Point Version");
              javalabs[0].setActionCommand(messageCommand2);
              javalabs[1] = new JRadioButton("Lab 03 100 Point Version");
              javalabs[1].setActionCommand(messageCommand3);
              javalabs[2] = new JRadioButton("Lab 04 100 Point Version");
              javalabs[2].setActionCommand(messageCommand4);
              javalabs[3] = new JRadioButton("Lab 04 Extra Credit 1");
              javalabs[3].setActionCommand(messageCommand41);
              javalabs[4] = new JRadioButton("Lab 04 Extra Credit 2");
              javalabs[4].setActionCommand(messageCommand42);
              javalabs[5] = new JRadioButton("Lab 05 100 Point Version");
              javalabs[5].setActionCommand(messageCommand5);
              javalabs[6] = new JRadioButton("Lab 05 Extra Credit");
              javalabs[6].setActionCommand(messageCommand51);
              javalabs[7] = new JRadioButton("Lab 06A 100 Point Version");
              javalabs[7].setActionCommand(messageCommand6);
              javalabs[8] = new JRadioButton("Lab 06B 100 Point Version");
              javalabs[8].setActionCommand(messageCommand6b);
              javalabs[9] = new JRadioButton("Lab 07 100 Point Version");
              javalabs[9].setActionCommand(messageCommand7);
              javalabs[10] = new JRadioButton("Lab 07 Extra Credit");
              javalabs[10].setActionCommand(messageCommand71);
              javalabs[11] = new JRadioButton("Lab 08A 100 Point Version");
              javalabs[11].setActionCommand(messageCommand8);
              javalabs[12] = new JRadioButton("Lab 08B 100 Point Version");
              javalabs[12].setActionCommand(messageCommand8b);
              javalabs[13] = new JRadioButton("Lab 08 Extra Credit");
              javalabs[13].setActionCommand(messageCommand81);
              javalabs[14] = new JRadioButton("Lab 09A 100 Point Version");
              javalabs[14].setActionCommand(messageCommand9);
              javalabs[15] = new JRadioButton("Lab 09B 100 Point Version");
              javalabs[15].setActionCommand(messageCommand9b);
              javalabs[16] = new JRadioButton("Lab 09 Texas Flag");
              javalabs[16].setActionCommand(messageCommand9t);
              javalabs[17] = new JRadioButton("Lab 09 American Flag");
              javalabs[17].setActionCommand(messageCommand9a);
              javalabs[18] = new JRadioButton("Lab 09 Extra Credit 1");
              javalabs[18].setActionCommand(messageCommand91);
              javalabs[19] = new JRadioButton("Lab 09 Extra Credit 2");
              javalabs[19].setActionCommand(messageCommand92);
              javalabs[20] = new JRadioButton("Lab 09 Extra Credit 3");
              javalabs[20].setActionCommand(messageCommand93);
              javalabs[21] = new JRadioButton("Lab 10 A 100 Point Version");
              javalabs[21].setActionCommand(messageCommand0);
              javalabs[22] = new JRadioButton("Lab 10 B 100 Point Version");
              javalabs[22].setActionCommand(messageCommand0b);
              javalabs[23] = new JRadioButton("Lab 10 Extra Credit 1");
              javalabs[23].setActionCommand(messageCommand01);
              javalabs[24] = new JRadioButton("Lab 10 Extra Credit 2");
              javalabs[24].setActionCommand(messageCommand02);     
              for (int k = 0; k < numButtons; k++)
                   group.add(javalabs[k]);
              javalabs[0].setSelected(true);
              select = new JButton("Select Program");
              select.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e)
                        String command = group.getSelection().getActionCommand();
                        if (command == messageCommand2)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                 try
                                    Runtime.getRuntime().exec(new String[] {"cmd", "set classpath=D:/Documents and Settings/Yinon Michaeli/My Documents/CS/java/Labs02", "path C:/j2sdk1.4.0/bin", "java Lab020"});
                                    //File file = new File("java/Labs02");
                                    //Runtime.getRuntime().exec(new String[] {"rundll32", "url.dll,FileProtocolHandler","file:///" + file.getAbsolutePath()});
                                 catch (Exception a)
                                      JOptionPane.showMessageDialog(frame, "Error: Exception.", "Error", JOptionPane.ERROR_MESSAGE);
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand3)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand4)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand41)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand42)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand5)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand51)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand6)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand6b)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand7)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand71)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand8)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand8b)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand81)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand9)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand91)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand9t)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand9a)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand9b)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand92)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand93)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand0)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand0b)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand01)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand02)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        return;
              return create2ColPane(labDescription + ":", javalabs, select);     
         private JPanel createPane(String description, JRadioButton[] radioButtons, JButton showButton)
              int numChoices = radioButtons.length;
            JPanel box = new JPanel();
            JLabel label = new JLabel(description);
            box.setLayout(new BoxLayout(box, BoxLayout.PAGE_AXIS));
            box.add(label);
            for (int k = 0; k < numChoices; k++)
                box.add(radioButtons[k]);
            JPanel pane = new JPanel(new BorderLayout());
            pane.add(box, BorderLayout.PAGE_START);
            pane.add(showButton, BorderLayout.PAGE_END);
            return pane;
        private JPanel create2ColPane(String description, JRadioButton[] radioButtons, JButton showButton)
            JLabel label = new JLabel(description);
            int numPerColumn = radioButtons.length/2;
            JPanel grid = new JPanel(new GridLayout(0, 2));
            for (int k = 0; k < numPerColumn; k++)
                grid.add(radioButtons[k]);
                grid.add(radioButtons[k + numPerColumn]);
            JPanel box = new JPanel();
            box.setLayout(new BoxLayout(box, BoxLayout.PAGE_AXIS));
            box.add(label);
            grid.setAlignmentX(0.0f);
            box.add(grid);
            JPanel pane = new JPanel(new BorderLayout());
            pane.add(box, BorderLayout.PAGE_START);
            pane.add(showButton, BorderLayout.PAGE_END);
            return pane;
        private static void createAndShowGUI()
             JFrame.setDefaultLookAndFeelDecorated(true);
             JFrame frame = new JFrame("Java Programs");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JavaMenu newContentPane = new JavaMenu(frame);
            newContentPane.setOpaque(true);
            frame.setContentPane(newContentPane);
            frame.pack();
            frame.setVisible(true);
        public static void main(String[] args)
             javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
    }

    Why are you posting hundreds of lines of code not related to the problem??? 99.9% of the code you posted has absolutely nothing to do with using the Runtime.exec() method.
    Create a simple test program that simply tries to invoke the Runtime.exec() method. Once you get that working, then you incoporate it into you real program. Don't clutter the forum with unnecessary code.
    public class WindowsFileProtocolHandler
         public static void main(String[] args)
              throws Exception
              String[] cmd = new String[4];
              cmd[0] = "cmd.exe";
              cmd[1] = "/C";
              cmd[2] = "java";
              cmd[3] = "YourClassHere";
              Process process = Runtime.getRuntime().exec( cmd );
    }

  • How do I copy a file to a remote server using runtime exec - plz Help!

    Hi,
    I am trying to copy a file to a remote server using a runtime exec command as follows:
    Runtime.getRuntime().exec("scp "+getProperty(ListNewHandsetDetailsConstant.PROP_OUTPUT_PATH_JAR)+getProperty(ListNewHandsetDetailsConstant.PROP_OUTPUT_JAR_NAME)+".jar "+" "+getProperty(ListNewHandsetDetailsConstant.PROP_OUTPUT_PATH_TWO_USERNAME)+"@"+getProperty(ListNewHandsetDetailsConstant.PROP_OUTPUT_PATH_TWO_URL)+":"+getProperty(ListNewHandsetDetailsConstant.PROP_OUTPUT_PATH_TWO_JAR));
    Problem is this statement does not execute, as when I try it directly on command line, it requests for a password. Any suggestions on how I can get rid of that? I think I might have to configure my ssh_config file, but when I did some "Googling", I found the configuration settings of a ssh2_config file. I tried those (changing it to Host-based Authentication), but it didn't recognise them. Please help, this is so urgent!
    Regards,
    Simz

    Don't use Runtime.exec (or ProcessBuilder) for this. Check out JSch at JCraft (or some other Java SSH API.

  • Problems with Runtime.exec inside OC4J in OAS!!! help!!

    Hi all,
    I have a method on my webapplication and the same call a script .cmd on windows and a .sh on unix using Runtime.exec command, inside this script have a call to a java program ie.
    java JMSAdmin < jcajms.txt
    OK, this is fine in OC4J Standalone 10.1.3 in windows and linux but in OAS 10.1.3 the same not run and not throw any error. Its is a BUG ?? limitation ?? OAS ignore a call to another java ??
    please help.
    Tanks

    Normally, you must prepend the command with a call to the command shell (eg /bin/sh).
    But I suspect that this call isn't allowed due to Java EE specification restrictions.

  • Runtime.exec help needed

    Hello,
    I am having a strange problem in using the Runtime.exec(command, null, workDirectory) method. Its giving an IOException and says:
    java.io.IOException: CreateProcess: delmembtrn-05.bat error=2
    at java.lang.Win32Process.create(Native Method)
    at java.lang.Win32Process.<init>(Win32Process.java:66)
    at java.lang.Runtime.execInternal(Native Method)
    at java.lang.Runtime.exec(Runtime.java:551)
    at java.lang.Runtime.exec(Runtime.java:418)
    at java.lang.Runtime.exec(Runtime.java:361)
    at java.lang.Runtime.exec(Runtime.java:325)
    Can anyone please guide me whats wrong here? I am trying to run a batch file which will run some java programs. I am running this program from one place and the batch file is in a different place(as represented by the workDir parameter in the exec method). This is holdin up my schedule. Someone can you please help me in this regard. Mail id: [email protected]

    I wanted to produce the same error before giving any advice - so i wrote:
    import java.lang.*;
    public class TestExec
         public static void main(String Arg[])
         throws Exception
              String command="go.bat";
              String envp [] = null;
              String workingDir="c:/temp/WorkingDir";
              Runtime.getRuntime().exec(command,envp,new java.io.File(workingDir) );
    }go.bat is not in path env var...
    I put go.bat into the workingDir and got this error:
    C:\TEMP\TestClass>java TestExec
    Exception in thread "main" java.io.IOException: CreateProcess: go.bat error=2
    at java.lang.Win32Process.create(Native Method)
    at java.lang.Win32Process.<init>(Unknown Source)
    at java.lang.Runtime.execInternal(Native Method)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at TestExec.main(TestExec.java:13)
    Looks pretty similar!
    After changing "go.bat" to "c:/temp/workDir/go.bat" it worked without error...
    So the conclusion is
    that the bat file command string does not specify the right directory
    or
    the bat file is not in the path string
    The working dir parameter is not added to the path env var...
    Tim Smith
    IncWorx

Maybe you are looking for

  • White screen, flashing folder, no hard drive?

    My 2009 macbook pro recently stopped working.. It suddently froze so i forced a shutdown.. I turned it on and it got stuck on a flash folder with a question mark.. I attempted to reinstall mavericks via boot usb and it was working but when asked wher

  • No dictation button on my keyboard

    i got the new ipad with 4G but i cant find the mic button on my keyboard? could someone plz help me? another thing! how can i make sure that my ipad is in deed the new ipad? thanks

  • Can't fill Color's in the Traced Image

    I have this image, of julie, what I did was that I copy and paste the image, then I made a new layer 2, I locked the first layer 1, and on the second layer where there is eye I pressed the ctrl+click on it to go to outline mode. I used the pen tool t

  • How to recieve emails in imessage?

    How I can recieve emails in my imessage?

  • Currencies in Leading ledger

    Friends, I am going to create non-leading ledger. My company in in US. for that company i am going to create non-leading ledgers for extension of business in india. In the above situation for existing company  2nd local currency and 3rd local currenc