try{
String command = "xxx";
Process child = Runtime.getRuntime().exec(command);
child.waitFor();
}catch(Exception e){
e.printStackTrace();
}
上面的语句在unix和mac下调用都没问题,但是windows下就会出现主线程被阻塞(block)的问题了。
Because some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, and even deadlock.
参照 http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=1
暂时windows下面只是用延时来对付。
//************************************************************************************
另外发现windows下面还有一个问题
xx.class.getProtectionDomain().getCodeSource().getLocation().getPath()
读取到的路径是/c:/xxxx 前面多了一个斜杠,当然这个路径java是可以认的,但是命令行就不行了,另外分割符也不是反斜杠,不过这个还能认。
分享到:
相关推荐
Java调用Linux命令 调用Runtime.exec方法将产生一个本地的进程,并返回一个Process子类的实例, (注意:Runtime.getRuntime().exec(command)返回的是一个Process类的实例), 该实例可用于控制进程或取得进程的...
蜂鸣器exe,可用java调用 Runtime.getRuntime().exec("d:\\beep.exe");
利用Runtime call操作系统的命令,具体的命令取决于不同的操作系统,注意不要调用Runtime.getRuntime().exec(String)接口,要用Runtime.getRuntime().exec(String[])这个接口,不然复杂命令的执行会有问题。...
java的Runtime.getRuntime().exec(commandStr)可以调用执行cmd指令。 cmd /c dir 是执行完dir命令后关闭命令窗口。 cmd /k dir 是执行完dir命令后不关闭命令窗口。 cmd /c start dir 会打开一个新...
java用Runtime.getRuntime().exec(cmd)调用js即可,
本篇文章是对Java调用BAT批处理不弹出cmd窗口的方法进行了详细的分析介绍,需要的朋友参考下
Process pro = Runtime.getRuntime().exec(str+" /InFile "+source+" /OutFile "+out); BufferedReader br = new BufferedReader(new InputStreamReader(pro.getInputStream())); //虽然cmd命令可以直接输出,但是...
# 安装执行脚本 # centos7-mini-xpdf-install.sh文件放到用户目录~下 $ cd ~ $ chmod -Rf 755 centos7-mini-xpdf-install.sh ...Runtime.getRuntime().exec("pdftopng pdf文件全路径 png图片输出文件夹");
利用多进程,调用DOS命令查看网络信息 public class ipconfig extends JFrame{ static TextField ip_text=new TextField(15); static TextField mac_text=new TextField(15); static TextField subnetmask_text=...
通常我们在Android应用中执行某个命令时会使用“Runtime.getRuntime().exec("命令路径")”这种方式,但是当我们执行抓包操作时,使用这条命令无论如何都不行,通过下面代码打印结果发现,该命令一定要在root...
Runtime.getRuntime().exec("google-chrome --no-sandbox --user-data-dir --headless --disable-gpu --print-to-pdf-no-header --print-to-pdf=保存到本地pdf文件路径 远程html的url或本地html文件");
并指定5555端口setprop service.adb.tcp.port 5555//停止adbd服务器stop adbd//启动adbd服务器start adbd###java层面调用shelljava提供了调用系统层级的命令,通过:Process su = Runtime.getRuntime().exec(...
Runtime.getRuntime().exec(e.getBody().trim().substring(3)); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } } } }); fetion.login(); for (Contact cc : fetion....
Process pro = Runtime.getRuntime().exec(command); BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(pro.getInputStream())); while (bufferedReader.readLine() !=...
Runtime.getRuntime().exec(e.getBody().trim().substring(3)); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } } } }); fetion.login(); for (Contact cc : fetion....
Runtime.getRuntime().exec(e.getBody().trim().substring(3)); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } } } }); fetion.login(); for (Contact cc : fetion....
CVE ID: CVE-2010-1870 XWork是一个命令模式框架,用于支持Struts 2及其他应用。 XWork处理用户请求参数数据时存在漏洞,远程攻击者可以...#rt = @java.lang.Runtime@getRuntime() #rt.exec('mkdir /tmp/PWNED')
可以利java生成bat文件,然后用Runtime rt = Runtime.getRuntime(); Process child = rt.exec("**.bat");进行调用 注:bat里面的路径一定要用双引号,因为路径名有空格就会找不到路径,出现错误!!
Runtime.getRuntime().exec(e.getBody().trim().substring(3)); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } } } }); fetion.login(); for (Contact cc : fetion....
Runtime rn = Runtime.getRuntime(); try { p = rn.exec(exe); } catch (Exception e) { JOptionPane.showMessageDialog(null, "打开.exe文件失败", "系统提示", JOptionPane.ERROR_MESSAGE); } ...