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