我写这将在Linux的Ubuntu操作系统上运行一些安装工具Java程序的输入按键到命令行,我需要在相同的方法,只是使执行两个连续命令第一个完全执行,然后调用第二个。我曾尝试使用“\ n”来分隔两个命令,如下面的代码所示,但它不起作用。如何通过从Java应用程序
public static void main (String args[])
{
List<String> command = new ArrayList<String>();
command.add("spin");
command.add("-p");
command.add("-u100");
command.add("D:\\promela\\peterson.pml");
command.add("\n");
command.add("cc -o pan pan.c");
command.add("./pan");
String[] commandArray = command.toArray(new String[command.size()]);
ProcessBuilder pb = new ProcessBuilder(commandArray);
Process process;
try {
process = pb.start();
BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
BufferedReader errReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String errline, outline;
for(String s : command)
{
System.out.println(s + " ");
}
while ((outline = br.readLine()) != null)
{
System.out.println(outline);
}
while ((errline = errReader.readLine()) != null)
{
System.err.println(errline);
}
} catch (IOException e)
{
e.printStackTrace();
}
}
@MarcoForberg没有,我怎么可以通过CTRL +从Java进入? – Sami
啊忘了吧。错了。以为你需要在从控制台读取时通过输入。 –