Execution

After I have compiled a file using the following code i then want to execute it and display the output or a frame by executing it but it won't execute can somebody help please?

publicvoid compile()

{

try

{

//classpath = "set classpath=C:/Program Files/j2sdk1.4.0/bin/";

javacPath ="C:/Program Files/j2sdk1.4.0/bin/";

cmd = javacPath +"javac " + fileNameStr;

statusBar.setText("Compiling: "+fileNameStr);

Process compileProcess;

InputStream compileErrorStream =null;

int compileExitValue = 1;//indicating a non succesful compile

//compile code (wait for javac to finish)

try

{

//compileProcess1 = Runtime.getRuntime().exec (classpath);

compileProcess = Runtime.getRuntime().exec (cmd);

compileProcess.waitFor();

compileErrorStream = compileProcess.getErrorStream();

compileExitValue = compileProcess.exitValue();

}

catch (Exception ex)

{

ex.printStackTrace();

}

//check if compile was successful

if (compileExitValue == 0)

{

System.out.println ("Compilation successful!");

//if it was successful, we can build the java file

statusBar.setText("Compilation successful!");

}

else

{

//get and report the error

String errorStr ="";

int i;

try

{

while ((i = compileErrorStream.read()) != -1)

errorStr += ((char) i);

}

catch (Exception ex)

{

ex.printStackTrace();

}

System.out.println ("Compile error...");

System.out.println (errorStr);

statusBar.setText("Error Compiling: "+errorStr);

}

}

catch(Exception ex){}

}

I then want to execute this code and i used the following method but it won't work.

void execute()

{

try

{

javaPath ="C:/Program Files/j2sdk1.4.0/bin/";

fileName = fileNameStr.substring(0, fileNameStr.indexOf('.'));

System.out.println(fileName);

cmd = javaPath +"java " + fileName;

statusBar.setText("Executing: "+fileName);

Process executeProcess;

try

{

executeProcess = Runtime.getRuntime().exec (cmd);

}

catch(Exception e){}

}

}

The methods are both called when buttons are pressed. If someone can run this code and fix it so it will execute. I'm sort of pressed for time but pretty sure it is close to been finished.

Damien

[4347 byte] By [damoreallya] at [2007-10-1 7:54:21]
# 1
Can anyone help me with this problem?/
damoreallya at 2007-7-9 20:39:38 > top of Java-index,Developer Tools,Java Compiler...