如何让Runtime.getRuntime().exec(p)运行而不等待sleep 10?
目前它是错误的,它等待执行完成然后移动到下一个。我需要动态地让 exec 运行,这样 10 秒后它就可以杀死PresentationInProjector.jpg。
Example:
Runtime.getRuntime().exec("(sleep 10; echo '09|00|CC|01|83|88' | nc localhost 58888) &");
PlayThisSlideShow("PresentationInProjector.jpg");
根据文档exec(): http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Runtime.html#exec%28java.lang.String%29
在单独的进程中执行指定的字符串命令。
所以任何电话exec()
除非您使用过,否则不应阻止waitFor()
关于返回的过程Runtime
.
这是一个小例子(省略异常处理):
Process p=Runtime.getRuntime().exec("cmd.exe /c ping 127.0.0.1 -n 10");
System.out.println("Here 1");//this will execute immediately
try {
p.waitFor();
System.out.println("Here 2");//this will only be seen after +- 10 seconds and process has finished
} catch (InterruptedException ex) {
ex.printStackTrace();
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)