import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
public class Test1 {
public static void main(String args[]) throws UnsupportedEncodingException {
test();
}
private static void test() {
try {
Runtime r = Runtime.getRuntime();
Process p = r.exec("java SV");
InputStream es = p.getErrorStream();
byte[] buf = new byte[1024];
int i = 0;
while((i = es.read(buf)) != -1) {
System.out.println(new String(buf, 0, i));
}
} catch(IOException e) {
e.printStackTrace();
}
}
}
public class SV {
public static void main(String args[]) {
System.err.println("hello world!");
}
}
如上执行的话,会输出hello world ! 并两个换行 13 10
那如果换成这样执行
cmd /c start java SV
返回是一个空流,可以试一下