How can I execute a Perl script using the Ant exec

2019-05-26 10:42发布

问题:

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)



标签: perl ant exec