Possible Duplicate:
Java external program
I am trying to wrtie a program to write a command on a command line,
for example;
ipconfig
and then get the response of the command so I want to both write command to a command line and get its response. I have searched about it on the net and saw that apache cli is used to do this in Java but actually I did not clearly get how it can be done. Can you please help me about my situation with a few line of codes or tutorials about both writing and reading commands please?
Thank you all very much
See
Process
andProcessBuilder
classes.Specifically, you would create a
Process
.Process.getOutputStream()
gives anInputStream
, from which you read what the process's output. You also need to readProcess.getErrorStream()
for any errors that the process reports.Try this for inputting the user value.
You could start it as a
Process
and capture theInputStream
of the process as described here:Edit: I copied this code from above link, but the code seems wrong. Don't you need the output stream for this? Edit2: no.
Nice naming convention...