I guess what I'm asking is....

A

Ashanen

....the simplest way to have a very small Java program (eg "hello world")
actually entered in a text area, and when an " execute button" is pressed, it
will actually execute it as a program.

At present I am using that the tasks for the button would have to include
saving the text area contents as a Java file, then calling a dos process
somehow to compile and execute it. But I am unclear on how to do that (get it
to call the DOS process). Or even whether this is the simplest way of doing
this!
 
K

KC Wong

...the simplest way to have a very small Java program (eg "hello world")
actually entered in a text area, and when an " execute button" is pressed, it
will actually execute it as a program.

At present I am using that the tasks for the button would have to include
saving the text area contents as a Java file, then calling a dos process
somehow to compile and execute it. But I am unclear on how to do that (get it
to call the DOS process). Or even whether this is the simplest way of doing
this!

That is already done and available for free...
Visit http://www.beanshell.org/ and see for yourself.
 
P

Phil Earnhardt

...the simplest way to have a very small Java program (eg "hello world")
actually entered in a text area, and when an " execute button" is pressed, it
will actually execute it as a program.

At present I am using that the tasks for the button would have to include
saving the text area contents as a Java file, then calling a dos process
somehow to compile and execute it. But I am unclear on how to do that (get it
to call the DOS process). Or even whether this is the simplest way of doing
this!

Servlet engines are essentially doing this: going through the
compile-execute process and running the code. If you are really doing
"Hello, world!" kind of text-based stuff, that's a way to do it.

--phil
 
A

Ashanen

Is there a simple way go call a dos process or get a windows bat file to
execute by an instruction in the event handler for a JButton?
 
H

Herman Timmermans

Ashanen said:
Is there a simple way go call a dos process or get a windows bat file to
execute by an instruction in the event handler for a JButton?

Yes, use something like this :

import Java.lang.*;
import Java.io.*;

public class RuntimeExecTest {
public static void main(String[] args) {
Runtime rt = Runtime.getRuntime();
String[] callAndArgs = { "Notepad.exe",
"D:\\TEMP\\Test.txt" };
try {
Process child = rt.exec(callAndArgs);
child.waitFor();
System.out.println("Process exit code is:
" + child.exitValue());
}
catch(IOException e) {
System.err.println(
"IOException starting process!");
}
catch(InterruptedException e) {
System.err.println(
"Interrupted waiting for process!");
}
}
}

Hope this helps you further, brgds Herman
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top