<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 ...