I'm trying to run some command line operations through JAVA. One of my command requires enter to be pressed to complete. I don't know how to pass enter through java in middle of a command execution.
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class CommandLineMethods {
public static String executeCommand(String []command)
{
StringBuffer output = new StringBuffer();
Process p;
try{
p=Runtime.getRuntime().exec(command);
p.waitFor();
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while((line=br.readLine())!=null)
{
output.append(line + "\n");
}
}
catch(Exception e)
{
e.printStackTrace();
}
return output.toString();
}
public static void main(String...args)
{
String scriptsPath ="C:\\bip_autochain\\win64_x64\\scripts";
String scriptName="lcm_cli.bat";
String scriptArguments="lcmproperty C:\\TestNG_Auto\\resources\\LCMBiar_Import.property";
String []command = {"cmd.exe", "/c"," cd "+scriptsPath+" && "+ scriptName +" -"+scriptArguments};
String res = executeCommand(command);
System.out.println(res);
}
}
Last command which is running a script with some argument requires an enter to pressed to complete. How to achieve so?