How can I execute a Perl script using the Ant exec task?

佐手、 提交于 2019-12-07 19:23:07

问题


I currently have this in my Ant build script:

<exec dir="${basedir}" executable="perl">
    <arg line="${basedir}/version.pl -major"/>
</exec>

However, when that runs, I get this error message:

[exec] Could not open -major
[exec] Result: 2

To me, that says that what I have is trying to run a file called -major, which doesn't exist. The file is version.pl which takes an argument of -major.

How can I alter this to run version.pl with the argument -major?

Note that I am running the ant script on a Solaris machine, however cross-platform or solutions for other OSes are welcome for posterity.


回答1:


I made a quick little Perl script that didn't do a whole lot and ran it just fine passing command line arguments to it using Ant 1.5 on a Solaris box.

<project name="perly" basedir="." default="run">
    <target name="run">
        <exec executable="perl" dir="${basedir}">
            <arg value="version.pl"/>
            <arg value="-major"/>
        </exec>
    </target>
</project>

$ ant run

What I can't quite understand is how you are getting "Could not open -major". Is this a custom die message or something? Is there supposed to be a filename passed instead of major?




回答2:


You can try this:

<exec executable="perl" dir="${basedir}">
    <arg value="version.pl"/>
    <arg value="-major"/>
</exec>

On windows that is




回答3:


Try this if it works:

<exec dir="${basedir}" executable="./test.pl">
   <arg line="-major"/>
</exec>

From the ant exec doc:

dir: the directory in which the command should be executed.

So i guess it does a cd to the $dir and exec the $executable (shebang set)



来源:https://stackoverflow.com/questions/1227463/how-can-i-execute-a-perl-script-using-the-ant-exec-task

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!