strCmd = new String("cmd /c exp root/123456@testdb file=c:/zzz2.dat"); try {
Process p = java.lang.Runtime.getRuntime().exec(strCmd );
while (true) {
if (p.waitFor() == 0)
break;
}
} catch (Exception e) {
}调试时发现: 执行p.waitFor() 就不动了。以上cmd命令我直接在命令行下执行就没有问题。以上程序执行mysql备份命令mysqldump也没有问题。
Process p = java.lang.Runtime.getRuntime().exec(strCmd );
while (true) {
if (p.waitFor() == 0)
break;
}
} catch (Exception e) {
}调试时发现: 执行p.waitFor() 就不动了。以上cmd命令我直接在命令行下执行就没有问题。以上程序执行mysql备份命令mysqldump也没有问题。
1、getOutputStream();
2、getErrorStream();
3、getInputStream(); // 这个如果确认不需要输入,可以不管,但风险自担。
String s;
BufferedReader bufferedReader =
new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((s = bufferedReader.readLine()) != null)
{
System.out.println(s);//将回显内容打印出来
}
...
Process p = java.lang.Runtime.getRuntime().exec(strCmd );
InputStream is = p.getErrorStream();
if (is == null) {
sys.out("错误!");
}
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
while ((br.readLine()) != null) {
}
br.close();
isr.close();
is.close();
exitValue = String.valueOf(p.waitFor());
p.destroy();
public abstract int waitFor()
throws InterruptedException
Causes the current thread to wait, if necessary, until the process represented by this Process object has terminated. This method returns immediately if the subprocess has already terminated. If the subprocess has not yet terminated, the calling thread will be blocked until the subprocess exits. Returns:
the exit value of the subprocess represented by this Process object. By convention, the value 0 indicates normal termination.
看看这个api的说明就明白了啊,有没有子进程出现呢?