Java Runtime.getRuntime().exec() 执行带空格命令
2024-08-24 21:53:12
可执行文件路径如果包含空格,则在java中不能被获取到。
此时Debug一下,会发现 project=null. project.waitFor 的返回值为1.但是去源路径单击bat文件是可以正常运行的,说明问题出在文件路径上。
将文件路径中的空格用双引号引起来就可以了
原先的代码
String batpath = file.getCanonicalPath() + "\\resources\\runTest.bat";
//run bat file
Process project = Runtime.getRuntime().exec("cmd.exe /c " + batpath.);
int exitcode=project.waitFor();
//kill the process
project.destroy();
logger.info(exitcode);
修改后的代码
//run bat file
Process project = Runtime.getRuntime().exec("cmd.exe /c " + batpath.replaceAll(" ", "\" \""));
最新文章
- HTML块级元素
- 前端学PHP之PHP操作memcache
- TABLE CONTROL隐藏列和固定列的实现
- show processlist
- 在本地(Eclipse)运行第一个strom-starter例子
- GitHub上README.md教程
- http://www.w3cplus.com/animation/create-animated-text-fills.html
- ";NetworkError: 500 Internal Server Error - http://develop.console.aliyun.sinopec.com/ots/ots_queryOtsList.action?state=0";
- Mysql 记录
- Java I/O---概述
- PhpStorm中报 “Cannot run program git.exe, 系统找不到指定的文件”
- 最短路径问题(Floyd-Warshall模板)
- [POJ 2104]K-th Number【模板】(主席树)
- 初步认识thymeleaf:简单表达式和标签(二)
- cxListView和dbgrid联动
- sql 设计规范
- 转【翻译】怎样在Ubuntu 12.04上配置Apache SSL证书
- Linux动态链接库.so文件的创建与使用
- [Android Studio] Android Studio如何查看branch列表及切换branch(转载)
- (转)Akka学习笔记
热门文章
- 【译】在Asp.Net中操作PDF – iTextSharp - 使用表格
- java操作Excel处理数字类型的精度损失问题验证
- STM32 + RT Thread OS 学习笔记[二]
- 十天学习PHP之第四天
- HTML的表单元�
- Android组件:Fragment切换后保存状态
- TTimerThread和TThreadedTimer(都是通过WaitForSingleObject和CreateEvent来实现的)
- Hough变换在opencv中的应用
- 为什么出现Wide character in print at a14.pl line 41
- CIconListBox带图标的列表框类