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?

2

2 Answers 2

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:

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

Comments

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();"

Comments

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.