Problem with Runtime.exec() method

Hi All,
tring _cmd = "cmd /c ";
          cmd =cmd+"sqlldr ";
          cmd = cmd + " userid=" + userId + "/" + passwd + "@"+ tnsEntry;
cmd = cmd + " control=" + controlFilePath;
          cmd = cmd + " log=sql.log skip=1";
          System.out.println(_cmd);
     try{
                         Runtime r = Runtime.getRuntime();
                         Process process = r.exec(_cmd);
                         int exitVal = process.waitFor();
System.out.println("Process exitValue:********** " + exitVal);
               catch(RuntimeException re )
                    System.out.println("Failed to runtime run the process.123.."+re);
I ve used proc.exitValue() to print the value of int value
but i got exception
then i used proc.waitFor() and print the value of int I got value = 4
here it is
Process exitValue:= 4
could u please tell me what does it mean? how to solve if the value is 4?
Thanks in advance

Please don't cross-post, it is extremely rude.
Stick with the [original thread|http://forums.sun.com/thread.jspa?threadID=5329691&tstart=0].

Similar Messages

  • Problem with Runtime.exec()

    Hi,
    I'm having a problem with Runtime.exec() . I have a batch file with debug option to FTP the desktop file to mainframe. When I executed this in Windows it's shows me the responce from the server (like ' Transfer Completed' ) for my FTP commands. But when I launch this through java it's only shows the errors not the normal responces from the server. I need this responses to confirm the proper transfer of file.
    My Java Code:
    String strCommand = "cmd.exe /c " + outdirectory + batchfilename;
    boolean bWait = true;
    Runtime r = Runtime.getRuntime();
    Process pr = r.exec(strCommand);
    BufferedInputStream bis =new BufferedInputStream(pr.getInputStream ());
    int c=0;
    /** Outlet for IO for the process **/
    while (c!=-1) {
    c=bis.read();
    /**Now wait for the process to get finished **/
    if(bWait == true){
    pr.waitFor();
    pr.destroy();
    My Batch file is :
    FTP -n -d -s:C:\IT2.cmd > C:\tIT2.log
    EXIT
    Thanks
    Sathiesh

    Ahh, you are redirecting the standard out from the ftp command to a file, therefore no output is sendt back to your java code,
    you have to redirect the stderr stream, not the stdout stream in your batch file;
    FTP -n -d -s:C:\IT2.cmd 2> C:\tIT2.log(notice the "2>" instead of ">")
    Now your batch file should direct the error stream to the log, and the standard output back to the java program.
    (I'm used to UNIX streams, not NT, but the "2>" redirection should work on NT also I guess)

  • Problem with runtime.exec().It hangs Up

    Hi all,
    I am having a problem with the runtime.exec method.I am trying to execute linux commands using this method.For most of the commands it works fine.But when i tried to change the user with the su command in linux my program hung up.So please help me to get around this.any help would be highly appreciable..
    I am pasting the code..
    <code>
    Process p=null;
    int ch=0;
    try
    System.out.println("Before executing command");
    String unlock_command="sh changeuser.sh";
    p = Runtime.getRuntime().exec(new String[] {"/bin/sh","-c","su tony"});
    InputStreamReader myIStreamReader = new InputStreamReader(p.getInputStream());
    while ((ch = myIStreamReader.read()) != -1)
    System.out.print((char)ch);
    p.waitFor();
    int p_exitvalue = p.exitValue();
    System.out.println("After executing the command and the exit value = "+p_exitvalue);
    p.destroy();
    catch (IOException anIOException)
    System.out.println(anIOException);
    catch(Exception e)
    e.printStackTrace();
    </code>
    Thanks
    HowRYou

    Hi sabre,
    What you have pointed out is right.But if i change the user as root then it will not ask for a password.Isn't it.Anyway thank you for giving your suggestions.Can yoiu help me more.Waiting for all of your help.I will try to swoitch between different users othere than root by giving the password.So just help me.

  • Problems with runtime.exec()

    Hi All,
    I am having a problem using runtime.exec()
    in servlet to call a java file from the server.The server is a linux one and i am using a tomcat server-4.1.24 the server contains
    some java files which i need to invoke with the help of the servlet program so i try to use exec() in servlet to invoke a particular java file in the server.The program is compiling well but no information
    is displayed on the browser.Where in the servlet program i try to print the details of the particular java program that is in the server.For ur
    reference i will post the code :-
    import javax.servlet.http.*;
    import javax.servlet.*;
    import java.io.*;
    public class ExeServlet extends HttpServlet
    public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
    try
    String path = getServletContext().getRealPath("/var/jakarta/webapps/examples/WEB-INF/classes/ServletExample.java");
    /*Where it is the path of the java file that resides in the server machine(linux)Which i want to invoke and print its details on the browser*/
    Runtime runtime=Runtime.getRuntime();
    Process proc=runtime.exec(path );
    BufferedReader br=new BufferedReader(new InputStreamReader(proc.getInputStream()));
    res.setContentType("text/html");
    PrintWriter pw=res.getWriter();
    pw.println("<b>");
    String line=null;
    while((line=br.readLine())!=null)
    { pw.println(line); //Displaying the details of the ServletExample.java file in the browser
    pw.println("</b>");
    catch (Exception e)
    pw.println("Listener *not* started!");
    What is the problem here?I was so frustrated with this.Pls. do provide an immediate reply if there is any code regarding this is working pls. do provide it.It is Urgent.I will be waiting for ur reply.
    Thanx,
    m.ananthu

    Hi Leo,
    Thank u for the reply i still have the problem with exec() in servlets.Has i said earlier in my previous mail by using exec() i trying to execute the output of a c-program for eg,Hello.run which provides an output of "HelloWorld" which is a sample eg.The Hello.run is the directory /var/jakarta/webapps/examples/WEB-INF/classes which is also the directory where my servlet program is.Where i am using a tomcat server-4.1.24 on the linux machine 7.3.Which is the server ofcourse.
    Here by using a servlet program i try to exceute the Hello.run c-program and display the output in the browser.This is what i need to do.
    I also used a sample core java class put the exec() there in a method and i try to call the method in the servlet.Which is also not working.
    Here is that example :-
    The core java program:-
    public class UsingExec
    public String ExeDisplay()
         try
    System.out.println("ExeDisplay");
         Runtime rt=Runtime.getRuntime();
         Process p=rt.exec("/var/jakarta/webapps/examples/WEB-INF/classes/Hello.run");
    p.waitFor();
    return "true";
         catch(Exception e)
    return "false";
    public static void main(String args[])
    UsingExec ue=new UsingExec();
    ue.ExeDisplay();
    When i run this program only ExeDisplay at the top is displayed.
    Here is the Servlet program:-
    import javax.servlet.http.*;
    import javax.servlet.*;
    import java.io.*;
    public class ExeServlet extends HttpServlet
    public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
    try
    res.setContentType("text/html");
    PrintWriter pw=res.getWriter();
    UsingExec ue=new UsingExec();
    String line=ue.ExeDisplay();
    pw.println(line);
    catch (Exception e)
    When i display this program on the browser only "false" is displayed from the UsingExec.java & nothing is displayed.
    Thanx,
    m.ananthu

  • 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.

  • Any problem with Runtime.exec()

    I am required to launch a local exe from an applet. At present I am using AppletContext.showDocument().The problem with this is that in netscape a box is popped up forcing the user to save that exe file. The requirwment is to run it directly without any message being asked.
    A workaround is to use Runtime.exec(), it works, however I have heard that it is not platform independent.
    (1) Is there a better solution than Runtime.exec() ?
    (2) If not could you give me some info on Runtime.exec() and the problems associated with it ?
    (3) Is there a way to use AppletContext.showDocument() without the message being asked ?
    Shikari.

    First of all, Java is platform independent language, and has many security restriction in it's applets.
    so from an applet you can't excute a program using "Runtime.getRuntime().exec()".
    coz. there is security restriction on that.
    for the "AppletContext.showDocument()" this methid is for displaying the specified document on the client browser, so it can't excute a client program.
    if u need to use Runtime.getRuntime().exec() you have to get the client agreement for that.
    see the applet security restriction for more info.

  • InputStream problem with Runtime.exec

    Dear all,
    I am writing a java application which is executing an external program (through threads). I am trying to read the output of that program while is in execution. Anyway i found out that InputStreamReader is not ready unless enough output of program is coming or the program exits.
    I simplified things writing the following small C program:
    main(){
    printf("Just a print\n");
    for(;;){} //Or anything that might keep program in execution
    So i am trying to find out why i cant get the output of this program unless it exits. Is this a problem with the underlying Stream? Is there any workaround?
    Thanks for any help.

    You are right. The C code is that of an external program that i am trying to execute and get its output. Actually i am working on a bigger program that it prints Directories recursively. To keep things simpler i used that simple C program to explain my problem.
    The code i am using is the following:
    /* WindowsExec.java */
    import java.io.*;
    public class WindowsExec
         response std_out,std_err;
         public WindowsExec(){
         try{
         String[] cmd = new String[]{"dark.exe"};
    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec(cmd);
    std_out = new response(proc.getInputStream(),System.out);          std_err = new response(proc.getErrorStream(),System.err);
    std_out.start();
         std_err.start();     
    int exitVal = proc.waitFor();
    System.out.println("ExitValue: " + exitVal);
                   proc.destroy();
         } catch (Throwable t){
              t.printStackTrace();
    public static void main(String args[]){
              new WindowsExec();
    /* Response.java */
    import java.io.*;
    class response extends Thread
         InputStream is;
         PrintStream type;
         public response(InputStream is, PrintStream type){
              this.is = is;
              this.type = type;
         public void run(){
         try{
              InputStreamReader isr = new InputStreamReader(is);
    while(true){
    if(isr.ready()){
    System.out.println("Its ready!"); //HERE!!!
              break;     
    BufferedReader br = new BufferedReader(isr);
    String line = null;
    while ( (line = br.readLine()) != null){
    System.out.println(line);
                   isr.close();
                   is.close();
              catch (Exception ioe){
    ioe.printStackTrace();
    Notice that i am never getting isr.ready() = true!

  • Problems with Runtime.exec() and certain Unix processes

    Certain Unix processes don't behave correctly when run from Java using Runtime.exec(). This can be seen by running /bin/sh and trying to interact with it interactively. The issue appears to be that /bin/sh (and many other Unix tools) are checking the file handles on the spawned process to see if they are associated with a TTY.
    Is there any way to associate a process spawned by Runtime.exec() with a terminal or alternatively, is there a JNI library available that would setup the process correctly and still provide access to the input and output streams?
    Our objective is to have the flexibility of expect in being able to run and interact with spawned processes. A bug was opened at one point but closed back in 1997 as being a fault in the spawned process, not Java.
    Bug ID: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4058689

    #include <stdio.h>
    void doit() {
    int c;
            while((c=getc(stdin)) != EOF) {
                    printf("%c",c);
    int main() {
            freopen("/dev/tty", "r", stdin);
            doit();
    }This program reopens its standard input against /dev/tty and catenates it to stdout. And voila, it takes its standard input from the terminal, even though it was started with stdin against /dev/null..
    $ gcc b.c -o b
    $./b < /dev/null
    buon giorno
    buon giorno

  • Newbie problem with "Runtime exec" "OutputStream"

    I am running an external process (Oracle Sqlplus) from a simple GUI using "Runtime exec". My problem is that I'm only able to retrieve input from the process after the Java output stream is closed. If I don't close the output stream my application does nothing. As soon as I close the output stream the input from the external process is printed to the screen and the external process is killed.
    I want to be able to start the external process once and then send and receive multiple input and output streams to it without having to stop and restart the process. Currently the only way to retrieve input from the process is to close the Java output stream which closes the process.
    Is this possible? Am I doing something wrong?
    I am new to Java so I appreciate your help.
    My code is below. I am running it on Windows 2000 Workstation, Java 1.4.1, Oracle 8.1.7.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    class ProcessTest extends JFrame implements ActionListener {
        private JTextArea upperTextArea;
        private JTextArea lowerTextArea;
        private BufferedReader in;
        private BufferedWriter out;
        public ProcessTest() {
            initialiseComponents();
            setBounds(200, 200, 600, 400);
            setVisible(true);
        public void initialiseComponents() {
            Container contentP = getContentPane();
            contentP.setLayout(new BorderLayout());
            upperTextArea = new JTextArea("SELECT SYSDATE FROM DUAL;\n");
            lowerTextArea = new JTextArea();
            JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
                                                  new JScrollPane(upperTextArea),
                                                  new JScrollPane(lowerTextArea));
            splitPane.setDividerLocation(200);                                     
            JPanel buttonPanel = new JPanel();
            JButton runButton = new JButton("Start Process");
            runButton.addActionListener(this);
            JButton outputButton = new JButton("Write Output");
            outputButton.addActionListener(this);
            JButton flushButton = new JButton("Flush Output");
            flushButton.addActionListener(this);
            JButton closeOutputButton = new JButton("Close Output");
            closeOutputButton.addActionListener(this);
            JButton inputButton = new JButton("Read Input");
            inputButton.addActionListener(this);
            buttonPanel.add(runButton);
            buttonPanel.add(outputButton);
            buttonPanel.add(flushButton);
            buttonPanel.add(closeOutputButton);
            buttonPanel.add(inputButton);
            contentP.add(buttonPanel, BorderLayout.NORTH);
            contentP.add(splitPane, BorderLayout.CENTER);
        public void startProcess() {
            try {
                Process process = Runtime.getRuntime().exec("sqlplus -S " +
                                                             "scott/tiger");
                in = new BufferedReader(new InputStreamReader(
                                         process.getInputStream()));
                out = new BufferedWriter(new OutputStreamWriter(
                                          process.getOutputStream())); 
                System.out.println("Process Started.");                         
            catch(IOException e) {
                e.printStackTrace();
        public void writeOutput() {
            try {
                out.write(upperTextArea.getText().toCharArray());
                System.out.println("Output Write Completed.");
            catch (IOException e) {
                e.printStackTrace();
        public void flushOutput() {
            try {
                out.flush();
                System.out.println("Output Flush Completed.");
            catch (IOException e) {
                e.printStackTrace();
        public void closeOutput() {
            try {
                out.close();
                System.out.println("Output Close Completed.");
            catch (IOException e) {
                e.printStackTrace();
        public void readInput() {
            try {
                lowerTextArea.read(in, lowerTextArea);
                System.out.println("Input Read Completed.");
            catch (IOException e) {
                e.printStackTrace();
        public void actionPerformed(ActionEvent e) {
            String action = e.getActionCommand();
            if (action.equalsIgnoreCase("start process")) {
                Thread thread1 = new Thread(){
                    public void run(){
                        startProcess();
                thread1.start();
            else if (action.equalsIgnoreCase("write output")) {
                Thread thread2 = new Thread(){
                    public void run(){
                        writeOutput();
                thread2.start();
            else if (action.equalsIgnoreCase("flush output")) {
                Thread thread3 = new Thread(){
                    public void run(){
                        flushOutput();
                thread3.start();
            else if (action.equalsIgnoreCase("close output")) {
                Thread thread4 = new Thread(){
                    public void run(){
                        closeOutput();
                thread4.start();
            else if (action.equalsIgnoreCase("read input")) {
                Thread thread5 = new Thread(){
                    public void run(){
                    readInput();
                thread5.start();
        public static void main(String[] args) {
            new ProcessTest();
    }   

    At this point, I'm not getting the same results as you. I'm executing cmd.exe w/o args, and using the text area to do multiple directory listings in one go -- so far, the input thread has been able to keep up. Try copying & pasting the following below (I made a few changes to it). If it still doesn't work, it might help to know what operating system you're on, jdk version, etc..
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    class ProcessTest extends JFrame implements ActionListener {
        private BufferedReader in;
        private BufferedWriter out;
        private JTextArea upperTextArea;
        private JTextArea lowerTextArea;
        private ProcInThread pit;
        private class ProcInThread extends Thread {
            private BufferedReader in;
            private char[] cbuf = new char[8192];
            private int numRead;
            ProcInThread(BufferedReader in) {
                this.in = in;
            public void run() {
                Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
                do {
                    try {
                        numRead = in.read(cbuf, 0, cbuf.length);
                        if (numRead < 0) System.out.println("\n***END OF STREAM***\n"); // <-DEBUG CODE
                    } catch (IOException ex) {
                        ex.printStackTrace();
                    SwingUtilities.invokeLater(new Runnable() {
                        public void run() {
                            lowerTextArea.append(new String(cbuf, 0, numRead));
                } while (numRead != -1);
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
        public ProcessTest() {
            initialiseComponents();
            setBounds(200, 200, 600, 400);
            setVisible(true);
        public void initialiseComponents() {
            Container contentP = getContentPane();
            contentP.setLayout(new BorderLayout());
            upperTextArea = new JTextArea("dir\ndir\ndir\ndir\ndir\ndir\ndir\n");
            lowerTextArea = new JTextArea();
            JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
                                                  new JScrollPane(upperTextArea),
                                                  new JScrollPane(lowerTextArea));
            splitPane.setDividerLocation(200);
            JPanel buttonPanel = new JPanel();
            JButton runButton = new JButton("Start Process");
            runButton.addActionListener(this);
            JButton outputButton = new JButton("Write Output");
            outputButton.addActionListener(this);
            JButton flushButton = new JButton("Flush Output");
            flushButton.addActionListener(this);
            JButton closeOutputButton = new JButton("Close Output");
            closeOutputButton.addActionListener(this);
            JButton inputButton = new JButton("Read Input");
            inputButton.addActionListener(this);
            buttonPanel.add(runButton);
            buttonPanel.add(outputButton);
            buttonPanel.add(flushButton);
            buttonPanel.add(closeOutputButton);
            buttonPanel.add(inputButton);
            contentP.add(buttonPanel, BorderLayout.NORTH);
            contentP.add(splitPane, BorderLayout.CENTER);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        public void startProcess() {
            try {
                Process process = Runtime.getRuntime().exec("cmd.exe");
                in = new BufferedReader(new InputStreamReader(
                                         process.getInputStream()),8192);
                out = new BufferedWriter(new OutputStreamWriter(
                                          process.getOutputStream()),8192);
                pit = new ProcInThread(in);
                pit.start();
                System.out.println("Process Started.");
            catch(IOException e) {
                e.printStackTrace();
        public void writeOutput() {
            try {
                out.write(upperTextArea.getText().toCharArray());
                System.out.println("Output Write Completed.");
            catch (IOException e) {
                e.printStackTrace();
        public void flushOutput() {
            try {
                out.flush();
                System.out.println("Output Flush Completed.");
            catch (IOException e) {
                e.printStackTrace();
        public void closeOutput() {
            try {
                out.close();
                System.out.println("Output Close Completed.");
            catch (IOException e) {
                e.printStackTrace();
        public void readInput() {
        public void actionPerformed(ActionEvent e) {
            String action = e.getActionCommand();
            if (action.equalsIgnoreCase("start process")) {
                Thread thread1 = new Thread(){
                    public void run(){
                        startProcess();
                thread1.start();
            else if (action.equalsIgnoreCase("write output")) {
                Thread thread2 = new Thread(){
                    public void run(){
                        writeOutput();
                thread2.start();
            else if (action.equalsIgnoreCase("flush output")) {
                Thread thread3 = new Thread(){
                    public void run(){
                        flushOutput();
                thread3.start();
            else if (action.equalsIgnoreCase("close output")) {
                Thread thread4 = new Thread(){
                    public void run(){
                        closeOutput();
                thread4.start();
            else if (action.equalsIgnoreCase("read input")) {
                Thread thread5 = new Thread(){
                    public void run(){
                    readInput();
                thread5.start();
        public static void main(String[] args) {
            new ProcessTest();
    }

  • Problem with Runtime.exec(gcc -c...

    when I execute
    P=Runtime.exec("cmd.exe /C gcc -c file.c");
    I do not have any problem but ,I do not obtain the corresponding file .o
    Somebody can help me, please?

    Are you checking the command is running. Unless you read the output of the process you will not see any errors.
    try
         public static void main(String[] args) throws IOException, InterruptedException {
              Process p1 = Runtime.getRuntime().exec("cmd.exe /C echo hello");
              System.out.println("Exit code = " + p1.waitFor());
              // produces an error.
              Process p2 = Runtime.getRuntime().exec("cmd.exe /C dontecho hello");
              System.out.println("Exit code = " + p2.waitFor());
         }

  • A problem with "Runtime.exec"

    Hello!
    I'm just trying to call a Fortran executable in a Java program.
    I'm a beginner in Java language and I believed Runtime.exec was the solution. My code :
    try {
    Process process = null;
    Runtime runtime = Runtime.getRuntime();
    process = runtime.exec("<name>.exe");
    catch (IOException eio) {
    System.out.println("Error -- " + eio.toString());
    When I run the project, there's no error, but the executable is not called.
    Can anybody help me?

    process = runtime.exec("Make sure// you have the right// path to.exe");

  • Problem with Runtime,process method exec and jar

    I have a application in java and it execute a executable C with method exec.
    It work well. But when I make the jar file, I have the exucatable inside of jar, but I don't know like I have to write the executable's path in the method exec(".......")
    thank you and sorry for my english

    You can't. You have to use the zip mechanism and extract it before using it.

  • Strange problem with Runtime.exec()

    Hi,
    I have a c++ exe file which I have to execute from my Java code. First I used:
    Runtime.getRuntime().exec (filepath);
    where filepath is the path to the exe file. It didn't work. Then I used:
    Runtime.getRuntime().exec
    ("rundll32 SHELL32.DLL,ShellExec_RunDLL " + file.getAbsolutePath());
    where file is a File variable. Then it works. I don't understand what the difference is between the both of them. I found the second option in some java forum, but he didnot explain the difference between the two. Can anyone please explain.
    Thanks in advance

    If have started tomcat as a windoes service, you cannot call Runtime.exec

  • Problem to execute cvs command using Runtime.exec method

    Hello,
    I want execute this cvs command, with this options:
    cvs -d :pserver:[email protected]:/home/cvs/cvsroot rlog -S -d "2007/05/01<now" Project
    I tried to execute with Runtime.exec() :
    Runtime.exec("cvs -d :pserver:[email protected]:/home/cvs/cvsroot rlog -S -d \"2007/05/01<now\" Project");
    But I have an error because the smaller character is interpretate as a redirection, no as a smaller symbol.
    How I can do to use this command with Runtime.exec ?
    Thanks.
    Regards.

    Sorry,
    I had a typing mistake.
    I want say:
    Runtime.exec("cvs -d :pserver:[email protected]:/home/cvs/cvsroot rlog -S -d \"2007/05/01<now\" Project");
    Regards.

  • 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 );
    }

Maybe you are looking for

  • Problem with Output parameter  in HR function

    Hi, I have a function "Z" done with tx PE04, the country it's venezuela, and i define the IT table as entry and output parameter. When i run the payroll, ithe changes that i did by abap code in order to change one concept of the IT table doesn't appe

  • Problem in session tracking?

    Hi! i am facing trouble while tracking a session inside my struts application,i am using following code snipit public class MyRequestProcessor extends RequestProcessor { protected boolean processPreprocess ( HttpServletRequest request, HttpServletRes

  • Deleting/dropping/removing database using Enterprise Manager  (12c)

    Hi, I have run some searches and review the documentation... but I haven't found any way to drop/remove/delete databases using 12c EM. We have multi-instance environments (one physical server with several instances/database). And from time to time we

  • Magic Trackpad - incorrect Trackpad preference pane?

    Hey folks, Just bought a pretty magic trackpad for my late 2009 i7 iMac (10.6.4). Looks nice, but when I set it up, Software Update didn't see any update for my iMac. So I downloaded it directly from Apple and that seemingly went fine, but the Trackp

  • How can I get my iPad to Sync Automatically when I plug it in. The Option is greyed out.

    My iPad came set to Sync Automatically. At some point I unclicked this Option. Now I would like to reset that option to AutoSync again. The option in iTunes is greyed out and I can not figure out how to get it to come back.