java Runtime.getRuntime().exec 调用系统脚本/命令注意事项
2016-01-28 10:03
633 查看
错误的方法:
//CPUID
private static final String cpuid="dmidecode -t processor | grep 'ID' | head -1";
Process p = Runtime.getRuntime().exec(cpuid);
原因:不会被再次解析,管道符失效
正确的办法:
linux下:
String[] command = { "/bin/sh", "-c",
cpuid };
Process ps = Runtime.getRuntime().exec(command );
windows下:
String[] command = { "cmd", "/c",
cpuid };
Process ps = Runtime.getRuntime().exec(command );
//CPUID
private static final String cpuid="dmidecode -t processor | grep 'ID' | head -1";
Process p = Runtime.getRuntime().exec(cpuid);
原因:不会被再次解析,管道符失效
正确的办法:
linux下:
String[] command = { "/bin/sh", "-c",
cpuid };
Process ps = Runtime.getRuntime().exec(command );
windows下:
String[] command = { "cmd", "/c",
cpuid };
Process ps = Runtime.getRuntime().exec(command );
相关文章推荐
- Java 中System里getProperty 方法获得系统参数
- 关于泛型数组
- Java并发编程:Callable、Future和FutureTask
- Java传值
- java 版本EChart使用
- SpringMVC之前后台分离开发,联调时的跨域问题的解决方法
- java中静态代码块的用法 static用法详解
- Spring3.1新特性
- Eclipse常用开发插件
- JAVA注解Annotation
- JAVA注解Annotation
- SpringMVC之前台post方式传递的json格式参数无法到后台
- java标识符和关键字
- SpringMVC上传图片与访问
- java生成验证码图片,包括动态gif图片格式
- Java编程规范
- Java判断身份证号码
- Spring MVC +Mybatis + Maven 配置之Dao配置
- MyEclipse中的快捷键
- 出现java.lang.UnsupportedClassVersionError 错误的原因