<project name="shell" default="execSH" basedir=".">
<target name="execSH">
<exec executable="${basedir}/shenjie.sh" failonerror="true">
</exec>
</target>
</project>
ant执行Linux的一个Shell脚本时,报Cannot run program "./script/setip.sh": java.io.IOException: error=2, No such file or directory]
java.io.IOException: Cannot run program "./script/setip.sh": java.io.IOException: error=2, No such file or directory
最终发现是这个shell脚本本身有问题,字符是windows格式(主要是换行符导致),用 vi 打开这个shell脚本就可以看到每一行后面有 ^M 的字符,把这个文件转到 Linux 格式就可以了,方法如下:
[root@localhost script]# dos2unix -o seip.sh
dos2unix: converting file seip.sh to UNIX format ...
本文介绍了解决ANT执行Shell脚本时遇到的错误问题,该错误提示为找不到指定的Shell脚本文件。经过排查,发现是由于脚本文件格式不匹配(Windows格式)导致在Linux环境下无法正确运行。通过使用dos2unix命令将Shell脚本转换为Linux格式,成功解决了此问题。
918

被折叠的 条评论
为什么被折叠?



