本人在做一个项目,部署在linux下,在winows下访问该网站,上传文件后使用Process调用shell程序,文件上传成功,但是Process没有运行成功,这是为什么啊?
代码如下
String SavePath="/storage2/image/";
Calendar calendar = Calendar.getInstance();
String filename = String.valueOf(calendar.getTimeInMillis());
String distPath =SavePath+filename+"."+getUploadFileName().substring(getUploadFileName().indexOf(".")+1);
System.out.println(getUploadFileName());
File disFile = new File(distPath);
copy(upload,disFile);
String name=distPath.substring(distPath.lastIndexOf("/")+1);
String shellCommand="/storage2/shell/a.sh "+name;
Runtime t=Runtime.getRuntime();
Process p=t.exec(shellCommand);
p.waitFor();
代码如下
String SavePath="/storage2/image/";
Calendar calendar = Calendar.getInstance();
String filename = String.valueOf(calendar.getTimeInMillis());
String distPath =SavePath+filename+"."+getUploadFileName().substring(getUploadFileName().indexOf(".")+1);
System.out.println(getUploadFileName());
File disFile = new File(distPath);
copy(upload,disFile);
String name=distPath.substring(distPath.lastIndexOf("/")+1);
String shellCommand="/storage2/shell/a.sh "+name;
Runtime t=Runtime.getRuntime();
Process p=t.exec(shellCommand);
p.waitFor();
chmod +x a.sh 设置一个权限试一下。
p.waitFor();
你在main函数中测试过shell命令没?这个shell有没有输出,如果有输出,则需要使用inputStream读取输出,并直接丢弃即可。
避免 缓冲区满。缓冲区满,程序会暂停执行......