转自:http://blog.csdn.net/zlpdaisy/article/details/6134314

用Runtime.getRuntime().exec()方法执行Linux的一个Shell脚本时,报

Cannot run program "./script/abc.sh": java.io.IOException: error=2, No such file or directory] java.io.IOException: Cannot run program "./script/abc.sh": java.io.IOException: error=2, No such file or directory

 

原因一:

最终发现是这个shell脚本本身有问题,字符是windows格式(主要是换行符导致),用 vi 打开这个shell脚本就可以看到每一行后面有 ^M 的字符,把这个文件转到 Linux 格式就可以了,方法如下:

 

解决方法:

[root@localhost script]# dos2unix -o abc.sh dos2unix: converting file abc.sh to UNIX format ...

 

原因二:

shell 脚本所带参数中含有JAVA中不可解释的字符,如“*”;误转移字符“$”,“-”

 

解决方法:

在之行命令前面叫上“sh -c”

[root@localhost script]# sh -c "abc.shtest

相关文章:

  • 2021-12-04
  • 2022-03-05
  • 2021-09-23
  • 2021-10-08
  • 2021-12-26
  • 2021-10-15
猜你喜欢
  • 2021-11-25
  • 2021-08-09
  • 2022-12-23
  • 2022-12-23
  • 2022-03-05
  • 2022-12-23
相关资源
相似解决方案