0
我正在编写一个javacode来调用交互式shellScript并使用进程生成器来调用shellscript。我知道要传递参数给这个shell脚本,我必须通过输入流来检查它的输出,并且需要使用输出流来传递命令。我的问题是,我怎么会知道使用输入流它提示输入值?使用java运行交互式shellScript
我的代码:
ProcessBuilder pb2=new ProcessBuilder("/home/abhijeet/sample1.sh","--ip="+formobj.getUpFile().getFileName(),"--seqs="+seqs);
script_exec = pb2.start();
OutputStream in = script_exec.getOutputStream();
InputStreamReader rd=new InputStreamReader(script_exec.getInputStream());
pb2.redirectError();
BufferedReader reader1 =new BufferedReader(new InputStreamReader(script_exec.getInputStream()));
StringBuffer out=new StringBuffer();
String output_line = "";
while ((output_line = reader1.readLine())!= null)
{
out=out.append(output_line+"/n");
System.out.println("val of output_line"+output_line);
//---> i need code here to check that whether script is prompting for taking input ,so i can pass it values using output stream
}
有没有什么办法可以直接知道脚本正在等待来自用户的输入?
我的问题是一样的,我不知道怎么会检查输入提示?然后我可以使用outputstream设置值。 –
您可以逐行读取进程输出流,是吗?当你阅读下一行时,你必须检查这一行的关键输入序列 – Sharkman
看看我已附加到答案的代码 – Sharkman