小布老师视频:
http://www.boobooke.com/bbs/viewthread.php?tid=7630&extra=page%3D1
linux命令 网址:
http://linux.chinaitlab.com/special/linuxcom/
這是怎麼回事兒呀?bash: ./abc.sh: cannot execute binary file
好像裡面有非法字符 :?:
這樣試試:
$at file
#!/bin/bash
echo $PATH
$bash file
当shell脚本中含有非法字符时,会出现上述错误。所以在编写shell脚本时,最好不好直接粘帖,想要粘帖,可以用文本的形式粘帖,例如
#!/bin/sh
在脚本刚开始一行中,粘帖中会吧“!”字符的格式也相应粘帖过来,从而导致上述错误提示,使用vi命令修改后,可以正常运行脚本
在sh文件中加入一行空行就ok了
if (proc.waitFor() != 0) {
logger.error("ִcmd [" + cmd + "] and returen is " + proc.exitValue());
return false;
} else {
return true;
}
java.io.IOException: ./shell.sh: cannot execute
at java.lang.UNIXProcess.fullPath(UNIXProcess.java:366)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:172)
at java.lang.ProcessImpl.start(ProcessImpl.java:114)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:466)
at java.lang.Runtime.exec(Runtime.java:607)
at java.lang.Runtime.exec(Runtime.java:480)
at com.huawei.fms.probe.service.common.FtpProtocol.downLoadUnzip(FtpProt
ocol.java:310)
at com.huawei.fms.probe.service.common.FtpProtocol.download(FtpProtocol.
java:203)
at com.huawei.fms.probe.service.common.FtpProtocol.main(FtpProtocol.java
:62)
JavaShellUtil javaShellUtil = new JavaShellUtil();
//参数为要执行的Shell命令,即通过调用Shell脚本sendKondorFile.sh将/temp目录下的tmp.pdf文件发送到192.168.1.200上
int success = javaShellUtil.executeShell("sh /tmp/sendKondorFile.sh /temp tmp.pdf");
经过研究,正确的程序如下:
public class test{
public static void main(String args[]){
Runtime rt=Runtime.getRuntime();
String str[]={"/bin/sh","-c","sh test.sh"};
Process pcs=rt.exec(str);
BufferedReader br = new BufferedReader(new InputStreamReader(pcs.getInputStream()));
String line=new String();
while((line = br.readLine()) != null)
{
System.out.println(line);
}
try{
pcs.waitFor();
}
catch(InterruptedException e){
System.err.println("processes was interrupted");
}
br.close();
int ret=pcs.exitValue();
System.out.println(ret);
}
}
|