windows Ant exec - 无法运行程序 'start' CreateProcess 错误=2

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1920882/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 06:59:15  来源:igfitidea点击:

Ant exec - cannot run program 'start' CreateProcess error=2

windowsantexec

提问by Srinivas A

I can't run the windows 'start' using ant exec. Ant version 1.7.1.

我无法使用 ant exec 运行 Windows 'start'。蚂蚁版本 1.7.1。

Here is sample build.xml to recreate the problem

这是重新创建问题的示例 build.xml

<project name="test"  basedir="." default="test-target">
<target name="test-target">
        <exec executable="start">
            <arg line="cmd /c notepad" />  
        </exec>      
</target>
</project>

getting the following error when I execute this build file:

执行此构建文件时出现以下错误:

Execute failed: java.io.IOException: Cannot run program "start": Cre
ateProcess error=2, The system cannot find the file specified

My env is Windows XP, Ant 1.7.1 I am trying to run this from DOS prompt. I rule out any PATH related issues, as I could run 'start cmd /c notepad' from DOS promt manually.

我的环境是 Windows XP,Ant 1.7.1 我试图从 DOS 提示符运行它。我排除了任何与 PATH 相关的问题,因为我可以从 DOS 提示符手动运行“start cmd /c notepad”。

Any suggestions on how to fix this?

对于如何解决这个问题,有任何的建议吗?

cheers a s

欢呼作为

回答by beny23

start is not an executable but is an internal command of the cmd.exe shell, so to start something you'd have to:

start 不是可执行文件,而是 cmd.exe shell 的内部命令,因此要启动某些操作,您必须:

<exec executable="cmd.exe">
        <arg line="/c start notepad" />  
    </exec>

EDIT:

编辑:

For spawning multiple windows, this should work:

对于生成多个窗口,这应该有效:

<target name="spawnwindows">
    <exec executable="cmd.exe" spawn="yes">
        <arg line="/c start cmd.exe /k echo test1" />  
    </exec>
    <exec executable="cmd.exe" spawn="yes">
        <arg line="/c start cmd.exe /k echo test2" />  
    </exec>
</target>

but you mentioned that spawn="true" is not applicable for your environment, why is that?

但是您提到 spawn="true" 不适用于您的环境,这是为什么呢?

回答by cNoNim

my solution

我的解决方案

<project name="test"  basedir="." default="test-target">
<target name="start-init">
        <exec executable="where" outputproperty="START">
            <arg line="start" />
        </exec>
</target>
<target name="test-target">
        <exec executable="${START}">
            <arg line="cmd /c notepad" />  
        </exec>      
</target>
</project>

回答by cNoNim

How about <exec executable="start.exe">? Or start.bat ?

怎么样<exec executable="start.exe">?还是 start.bat ?

Also, where is basedir="."pointing to? If you place a <echo message="basedir = ${basedir}"/>just before your <exec>tag, does it print the correct folder (the one with the "start" program in it)?

还有,basedir="."指向哪里?如果您<echo message="basedir = ${basedir}"/><exec>标签之前放置一个,它是否会打印正确的文件夹(其中包含“开始”程序的文件夹)?

Additionally, you could add <echoproperties />before <exec>to see all visible properties.

此外,您可以添加<echoproperties />before<exec>以查看所有可见属性。