例如说我执行了如下的命令
Process proc = Runtime.getRuntime().exec("echo Hello");
现在我想获得命令行的输出,也就是说我要获得Hello这个字符串,我该怎么做?
好像Process有getOutputStream()的方法,但是直接toString()打印出来的是类名,我该怎么怎么获得Shell的输出呢
Process proc = Runtime.getRuntime().exec("echo Hello");
现在我想获得命令行的输出,也就是说我要获得Hello这个字符串,我该怎么做?
好像Process有getOutputStream()的方法,但是直接toString()打印出来的是类名,我该怎么怎么获得Shell的输出呢
int c = 0;
while((c = os.read()) != -1){
System.out.println((char)c);
}
不过得InputStream is = proc.getInputStream();
int c = 0;
while((c = is.read()) != -1){
System.out.print((char)c);
}
才能取得输出