0

I searched a lot the last hours to open program.exe and interact with it like cmd. The solutions I found did not work or just worked for opening cmd and running commands like 'dir'.

I want to open a program (lets say program.exe), entering a command, parsing the output and then entering the next command. The window of the command line does not have to be open/visible but I need to get the output and enter further commands. How can I do this with Java?

user1000742
  • 183
  • 2
  • 10
  • Is the [Java Tutorial on Command Line Arguments](http://docs.oracle.com/javase/tutorial/essential/environment/cmdLineArgs.html) what you are looking for? – assylias May 29 '12 at 17:14
  • Perhaps [this](http://stackoverflow.com/questions/3468987/executing-another-application-from-java) thread will give you some direction. – Web User May 29 '12 at 17:19

2 Answers2

2

I think what you may be referring to opening another process and running a command-line program from it and passing arguments to this secondary process.

If so, what you are looking for is the ProcessBuilder.

You can create a Process and obtain an input stream to read from it, or an output stream to write back at it.

You might want to check the following examples:

Edwin Dalorzo
  • 76,803
  • 25
  • 144
  • 205
0

You should have a look at Runtime. It is an object every application has and is there to interact with the environment. http://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html

You can start a program with "exec" which will return an Process instance. You can access the output stream by calling "process.getOutputStream();"

krishnakumarp
  • 8,967
  • 3
  • 49
  • 55
clentfort
  • 2,454
  • 17
  • 19