1

I try to get my penplotter to work from within java. I have a start but I don't know how to continue. This is what I have:

public static void main(String[] args) {

        try {
            Runtime runTime = Runtime.getRuntime();

            Process process = runTime.exec("chiplotle");


            BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));

            String line = null;

            System.out.println("this prints fine");


            while ((line = in.readLine()) != null) {
                System.out.println(line);
            }


            System.out.println("it never reaches this...");

        }
        catch (IOException e) {
            e.printStackTrace();
        }

    }

This is the output in the console:

IntelliJ console

I typed the 11 myself. But it doesn't do anything with it. Also it never prints:

System.out.println("it never reaches this...");

So it looks like my program is halted for input, is that correct? And how can I get further?

1
  • It just blocked i think while trying to read additional lines. Commented Mar 8, 2015 at 12:44

1 Answer 1

1
  1. You should read from the InputStream in a bacgkround thread.
  2. You need to get the Process's OutputStream and then write to it.

OutputStream os = process.getOutputStream();
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os));
PrintWriter pw = new PrintWriter(bw);

// now you can write to the Process, i.e., pw.println("11");

You will need to not just print but also to analyze the text that your InputStream sends you to decide when to write back to the process via the PrintWriter.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I think this should help me to continue!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.