0

I've been trying to code an app that allows me to open multiple Console sessions (in windows that would be cmd.exe) in a Tabbed fashion way.

One of the most important references I've found is in the following URL where I was able to get a TextAreaOutputStream code to be able to read the STDOUT fron the Process, but this and most of the references around the internet does not solve/fix the issue I'm dealing with.

Reference: Create Java console inside a GUI panel

Even when redirecting the STDOUT, STDERR and STDIN caused me some troubles, the worst part comes when the command you type within the Java Console in one of the tabs executes a command that creates a child process, it's here when my Java applications loses control because a new process was created in the background. Basically, the new child process is out of bound and I'm not able to receive or send any bytes to it and my app hangs.

  • JVM
    • MyTabbedConsoleApp
      • cmd.exe /k (I can still communicate with this one, no problems until here)
        • apptrack.exe (a child process out of bound from my app, no communication with this, the app hangs)

I'm looking for a better way to create an app that pretty much mimics the Console environment.

Community
  • 1
  • 1
mat060
  • 21
  • 1
  • 4
  • Unlike forum sites, we don't use "Thanks", or "Any help appreciated", or signatures on [so]. See "[Should 'Hi', 'thanks,' taglines, and salutations be removed from posts?](http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be-removed-from-posts). BTW, it's "Thanks in advance", not "Thanks in advanced". – John Saunders Jan 31 '15 at 19:59

1 Answers1

0

You should use ProcessBuilder instead of Runtime as it is the recommended API to deal with operating systems processes.

Check the Changes to Runtime.exec topic for the Java 6u45 Release Notes.

The preferred way to create operating systems processes since JDK 5.0 is using java.lang.ProcessBuilder. The ProcessBuilder class has a much more complete API for setting the environment, working directory and redirecting streams for the process.

Evandro Pomatti
  • 13,341
  • 16
  • 97
  • 165
  • Do you know if ProcessBuilder supports the pipe redirection in case the main process executes or creates a different console or subprocess inside (nested processes). My main problem with Runtime.exec was that if mi process created another subprocess, the main process was waiting for the subprocess undefinitelly and I had no stdout information from the sub process. – mat060 Sep 27 '17 at 16:36
  • @mat060 I do not know about that, you should open a separate question for that. – Evandro Pomatti Sep 28 '17 at 19:58