如何同步java代码
发布时间:2020-12-15 08:33:00 所属栏目:Java 来源:网络整理
导读:我有下一个代码: Process p = Runtime.getRuntime().exec(args); 我希望我的程序等待Runtime.getRuntime().exec(args);完成导致它持续2-3秒,然后继续. 想法? 解决方法 这是一个示例代码: Process proc = Runtime.getRuntime().exec(ANonJava.exe@);InputS
我有下一个代码:
Process p = Runtime.getRuntime().exec(args); 我希望我的程序等待Runtime.getRuntime().exec(args);完成导致它持续2-3秒,然后继续. 想法? 解决方法
这是一个示例代码:
Process proc = Runtime.getRuntime().exec(ANonJava.exe@); InputStream in = proc.getInputStream(); byte buff[] = new byte[1024]; int cbRead; try { while ((cbRead = in.read(buff)) != -1) { // Use the output of the process... } } catch (IOException e) { // Insert code to handle exceptions that occur // when reading the process output } // No more output was available from the process,so... // Ensure that the process completes try { proc.waitFor(); } catch (InterruptedException) { // Handle exception that could occur when waiting // for a spawned process to terminate } // Then examine the process exit code if (proc.exitValue() == 1) { // Use the exit value... } 您可以在此站点上找到更多信息:http://docs.rinet.ru/JWP/ch14.htm (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |