| Author |
Multiple inputs for Java Runtime
|
Mani Venkata Kanth
Ranch Hand
Joined: Aug 21, 2006
Posts: 39
|
|
I have a batch file which will 3 inputs one by one.
Its like 'changepassword.bat' with below inputs:
Old Pwd:
New Pwd:
Confirm Pwd:
User need to enter each input and press enter to enter second input.
Now, I am planning to simulate the same in java program.
For this I am using Runtime.exec();
I am writting inputs to outputStream which is the process.getOutputStream() like below:
out.write(bytes1);
out.write(System.getProperty("line.separator").getBytes());
out.write(bytes2);
out.write(System.getProperty("line.separator").getBytes());
out.write(bytes2);
out.flush();
out.close();
the process is being started and keep on waiting for the input.
I am assuming that the process is taking all my data written to stream as single input like ,
(byte1\nbyte2\nbyte3)
and waiting to either <enter> event or for other inputs.
Please help me solving this issue. or suggest any other approach.
|
 |
N Sahni
Ranch Hand
Joined: Jul 07, 2011
Posts: 55
|
|
Hi,
This topic should give you different approaches for reading inputs in Java. we-ask-user-input-writing
|
Thanks and Regards,
Nilesh Sahni | nsahni@infocepts.com | www.infocepts.com
|
 |
Mani Venkata Kanth
Ranch Hand
Joined: Aug 21, 2006
Posts: 39
|
|
Hi Sahni,
My question is not reading the input dynamically... its about writting multi line input to the Java Runtime Process.
Thanks
|
 |
N Sahni
Ranch Hand
Joined: Jul 07, 2011
Posts: 55
|
|
ohh I took the question in other way.
In this case, may be you can parameterize you batch file and pass all the inputs as parameters to the batch file.
|
 |
Darryl Burke
Bartender
Joined: May 03, 2008
Posts: 4167
|
|
Have you implemented all recommendations in all the sections of When Runtime.exec() won't? If not, first make sure you're consuming the output and error streams.
Even with that, I could make input to a .BAT work only by flush()ing the stream after each output and following that with a Thread.sleep(50). Maybe someone with a better understanding of batch files could explain why and/or suggest a better approach.
|
luck, db
There are no new questions, but there may be new answers.
|
 |
 |
|
|
subject: Multiple inputs for Java Runtime
|
|
|