Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How do I route the output from an external process to the output window?

0
Posted

How do I route the output from an external process to the output window?

0

Writing to the output window is tricky – typically you need to launch an external process via Runtime.exec(). The code that does this should not be running on the event thread. Then you need a couple of threads to monitor the standard out and error out of the process, and pipe any output to the output window. The following code is a rough example: public void launchProcess (String commandline) { if (EventQueue.isDispatchThread()) { throw new IllegalStateException (“Cannot be called from EDT”); } final Process process = Runtime.getRuntime().exec (cmdline); //Get the standard out InputStream out = new BufferedInputStream (process.getInputStream(), 8192); //Get the standard in InputStream err = new BufferedInputStream (process.getErrorStream(), 8192); //Create readers for each final Reader outReader = new BufferedReader (new InputStreamReader (out)); final Reader errReader = new BufferedReader (new InputStreamReader (err)); InputOutput io = IOProvider.getDefault().getIO(scene.getName(), f

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123