我写了一个Java命令行应用程序的Windows,并存储在一个字符串变量CMD的结果。
我的问题是:是否有可能得到这个变量的子从我所存储的CMD的输出?
我想提出,如果子在CMD输出字符串变量发现,创建一个动作的声明。
下面是应用类的方法:
public static void main(String[] args) throws IOException, InterruptedException
{
runWndCommand("ping 192.168.11.3");
}
public static void runWndCommand(String cmd) throws IOException, InterruptedException
{
Runtime runtime = Runtime.getRuntime();
Process p = runtime.exec(new String[] { "cmd.exe", "/C", cmd });
Scanner reader = new Scanner(p.getInputStream());
while (reader.hasNext())
{
String r=reader.nextLine();
System.out.println(r);
}
p.waitFor();
}