java 调用可执行文件时,ProcessBuilder异常CreateProcess error=2
2016-04-26 10:18
330 查看
java 调用其他应用程序时,可能在windows下没有问题,但是转到linux下,却会报这样那样的错误,比如有设计文件操作会报FileNotFoundException等等(如下代码):
原因: 不同的操作系统指令之间如果存在空格,可能会出现无法识别指令的错误。
解决方法: 指令中有空格的需要用不同的字符串分开,将指令用空格进行split,通过数组方式进行指令传值,使用API:
public ProcessBuilder command(String... command)
可参考ProcessBuilder 类说明:
Constructs a process builder with the specified operating system program and arguments. This is a convenience constructor that sets the process builder's command to a string list containing the same strings as the
Parameters:command a string array containing the program and its arguments
ProcessBuilder builder = new ProcessBuilder(); builder.command(ffmpeg -i /data/download_video/20160425/20160425235938929164582_1.flv -y -vcodec libx264 -vpre ultrafast -vpre baseline -cqp 28 -coder 0 -refs 3 -deblockalpha 1 -deblockbeta -1 -me_method umh -subq 9 -me_range 32 -trellis 2 -chromaoffset -2 -nr 0 -b_strategy 1 -bframebias 0 -directpred 3 -g 250 -i_qfactor 1.3 -b_qfactor 1.4 -flags2 +bpyramid+wpred+mixed_refs+8x8dct -acodec libfaac -s 640*360 -b 532000 -ab 58000 -r 15 -pass 1 /data/video/output/20160425/20160425235938929164582_1_06400360.mp4); builder.start(); 4 ..........
原因: 不同的操作系统指令之间如果存在空格,可能会出现无法识别指令的错误。
解决方法: 指令中有空格的需要用不同的字符串分开,将指令用空格进行split,通过数组方式进行指令传值,使用API:
public ProcessBuilder command(String... command)
可参考ProcessBuilder 类说明:
Constructs a process builder with the specified operating system program and arguments. This is a convenience constructor that sets the process builder's command to a string list containing the same strings as the
commandarray, in the same order. It is not checked whether
commandcorresponds to a valid operating system command.
Parameters:command a string array containing the program and its arguments
相关文章推荐
- download prebuild gcc
- compile,build和rebuild(vs2008)
- 优化UITableViewCell高度计算的那些事
- 隐藏UITableView多余的分割线
- req.getRequestDispatcher和resp.sendRedirect的区别
- 【bzoj4059】【Cerc2012】【Non-boring sequences】【分治】
- iOS UICollectionView 使用详解
- UIAlertController
- Keil中build和rebuild区别
- easyui datagrid插件的getChecked方法,只能获取一行
- ParseInt()与valueof()的区别
- 【Vue】 -(4) 数据绑定语法
- UIView动画
- 详解iOS应用中自定义UIBarButtonItem导航按钮的创建方法
- [CareerCup] 17.8 Contiguous Sequence with Largest Sum 连续子序列之和最大
- 针对网站的UI分析
- ubuntu14.04安装squirrelmail
- 矩阵快速幂 - hduoj 5667 Sequence -nyoj 301 递推求值
- 优化Duilib图片属性解析代码,提升绘制效率
- ECMAScript语句