php file from command line using windows


php file from command line using windows

我正在尝试运行一个ant脚本,该脚本被设置为执行各种php模块,例如

<target name="phploc" description="Measure project size using PHPLOC">
  <exec executable="${basedir}/build/tools/phploc.phar">
   <arg value="--count-tests" />
   <arg path="${basedir}/src" />
   <arg path="${basedir}/tests" />
  </exec>
 </target>

但是它失败了,错误为"%1不是有效的Win32应用程序"

我已经执行了注册表调整,如下所述。。。http://php.net/manual/en/install.windows.commandline.php

还为法尔重复了一遍。如果我打开一个命令窗口,我可以执行php或phar文件,只需键入它的名称,例如phploc.phar,而不是完整的php.exe phploc.par,但它不能通过ant工作。

如果我将ant文件更改为:

 <target name="phploc" description="Measure project size using PHPLOC">
  <exec executable="php">
   <arg line="${basedir}/build/tools/phploc.phar --count-tests" />
   <arg path="${basedir}/src" />
   <arg path="${basedir}/tests" />
  </exec>
 </target>

一切都很好,我想这被翻译成php.exe /build/tools/phploc.phar(或类似的东西)。

构建文件来自别人的项目,我已经通过git克隆了它,所以理想情况下我不想更改它

所以我想我不明白为什么它是通过命令行工作的(即识别.php.phar是可执行的),而不是通过ant。有什么区别?

谢谢!

注意:我在一台用作构建服务器(jenkins)的windows机器上安装了独立的php(没有apache)。PATH已更改为包含php目录。

Windows*.bat文件必须通过cmd运行。将您的示例更改为:

<target name="phploc" description="Measure project size using PHPLOC">
    <exec executable="cmd">
        <arg value="/c"/>
        <arg value="${basedir}/build/tools/phploc"/>
        <arg value="--count-tests" />
        <arg path="${basedir}/src" />
        <arg path="${basedir}/tests" />
    </exec>
</target>