可执行文件路径如果包含空格,则在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(" ", "\" \""));

最新文章

  1. HTML块级元素
  2. 前端学PHP之PHP操作memcache
  3. TABLE CONTROL隐藏列和固定列的实现
  4. show processlist
  5. 在本地(Eclipse)运行第一个strom-starter例子
  6. GitHub上README.md教程
  7. http://www.w3cplus.com/animation/create-animated-text-fills.html
  8. "NetworkError: 500 Internal Server Error - http://develop.console.aliyun.sinopec.com/ots/ots_queryOtsList.action?state=0"
  9. Mysql 记录
  10. Java I/O---概述
  11. PhpStorm中报 “Cannot run program git.exe, 系统找不到指定的文件” 
  12. 最短路径问题(Floyd-Warshall模板)
  13. [POJ 2104]K-th Number【模板】(主席树)
  14. 初步认识thymeleaf:简单表达式和标签(二)
  15. cxListView和dbgrid联动
  16. sql 设计规范
  17. 转【翻译】怎样在Ubuntu 12.04上配置Apache SSL证书
  18. Linux动态链接库.so文件的创建与使用
  19. [Android Studio] Android Studio如何查看branch列表及切换branch(转载)
  20. (转)Akka学习笔记

热门文章

  1. 【译】在Asp.Net中操作PDF – iTextSharp - 使用表格
  2. java操作Excel处理数字类型的精度损失问题验证
  3. STM32 + RT Thread OS 学习笔记[二]
  4. 十天学习PHP之第四天
  5. HTML的表单元�
  6. Android组件:Fragment切换后保存状态
  7. TTimerThread和TThreadedTimer(都是通过WaitForSingleObject和CreateEvent来实现的)
  8. Hough变换在opencv中的应用
  9. 为什么出现Wide character in print at a14.pl line 41
  10. CIconListBox带图标的列表框类