public static String executeCommand(String command) {
StringBuffer sb = new StringBuffer();
Process p;
try {
p = Runtime.getRuntime().exec(command);
p.waitFor();
} BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
} catch (Exception e) {
e.printStackTrace();
}
return sb.toString();
}
给定的代码工作正常,执行任何命令,但我有一个命令,要求是/否作为输入。我如何将输入提供给命令以进一步执行?带提示执行命令是输入
ex。
executeCommand("pio app data-delete model");
output-
[INFO] [App$] Data of the following app (default channel only) will be deleted. Are you sure?
[INFO] [App$] App Name: twittermodeling
[INFO] [App$] App ID: 14
[INFO] [App$] Description: None
Enter 'YES' to proceed:
所以我如何给予他们以进一步执行。
感谢
你能给我们一个例子,像输入字符串预期的行为? – Tirath
如果我得到它......你想使用由'p.waitFor()'返回的值来说出一个提示'Enter'YES'继续:'。 – Tirath