I am trying to build a little IDE that calls a C compiler. When the C compiler compiles, I want to redirect the output to a JTextArea or JEditorPane in the IDE so the user can view the output.
Also, after executing the object file from the compiled code, how do i create a cons开发者_如何转开发ole that the user can use to interact with the c program?
for instance if the C code requires the user to type an input, the user can do that from the console.
Basically, what i want is how to redirect a console input and output operations to a jtextarea or jeditorpane. I am building the IDE with java.
This question is broad (not concise), but some tips:
You can execute the external process by using
Process p = Runtime.getRuntime().exec("...").
The process you get represents the external process running and you can get its input and output with:
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
PrintWriter pw = new PrintWriter(p.getOutputStream());
With the br
you can read the output of the process, line by line and add it to a JTextArea
. With the pw
you can print to the input of the process in order to pass some data.
You should use a thread to read from the process continuously and add the data to the textarea. The data should be interpreted by the user and when he/she considers the process is requiring some input, should write it to a textarea and click a button (for example) and then you read the textarea and writes the data to the pw
.
精彩评论