response to the execution of an commande by code java
hello
in my java program I excecute a command through the code => it works
but as I stepped into the prog : I found myself with a command that requires an answer after his execution
then by java program: I do not know how to answer but in the command line I responds with yes and it works
do you have any idea how to respond through the java code
I hope you understand the question:
Here's the code I use for execute command DOS :
Code :
public static String importer_certificat(String alias,String nom_certi,String nom_keystore,String pass_keystore)
{
try{
String b = "keytool -import -alias "+alias+" -file "+nom_certi+" -keystore "+nom_keystore +" -storepass "+pass_keystore;
System.out.println(b);
Process p = Runtime.getRuntime().exec(b);
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String inputLine, tous = "";
while ((inputLine = in.readLine()) != null)
{
tous += "\n"+inputLine;
System.out.println(inputLine);
}
return tous;
}catch(Exception e)
{
e.printStackTrace();
return e.getMessage();
}
}
thank you in advance
Re: response to the execution of an commande by code java
The Process class has methods for getting streams for output from the process and for input to the process. See the API doc
Re: response to the execution of an commande by code java
Re: response to the execution of an commande by code java
Here is a link to the API doc:
Java Platform SE 6