0

I'm trying to code my own little Java IDE in Java. I'm pretty far for what I want, because I only want to be able to code simple command-line-programs in my IDE.

My current problem has to do with user input.

This is how I handle having an own console-output in my IDE (outputField is a jTextArea):

try {
    Process p = Runtime.getRuntime().exec(cmd);
    BufferedReader readerInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
    BufferedReader readerError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
    //BufferedWriter processInput = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
    String outputLine;
    while ((outputLine = readerInput.readLine()) != null) {
        outputField.append(outputLine + "\n");
    }
    while ((outputLine = readerError.readLine()) != null) {
        outputField.append(outputLine + "\n");
    }
} catch (IOException e) {
    e.printStackTrace();
}

But I have no idea how I could get user input to satisfy the scanner if a user written console-application asks for user input via a scanner. Right now my IDE would just freezes. Probably because the command-line-program waits for user input? Maybe I should run it in a different thread. How would I do that?

Maybe someone can get me some keywords I could research etc.

Greetings, Daniel

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
premaider
  • 41
  • 6

0 Answers0