Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

windows

exec

ant

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

Here is sample build.xml to recreate the problem

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

Any suggestions on how to fix this?

cheers a s

like image 510
Srinivas A Avatar asked Dec 17 '09 10:12

Srinivas A


2 Answers

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

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

like image 110
beny23 Avatar answered Oct 04 '22 10:10

beny23


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>
like image 45
cNoNim Avatar answered Oct 04 '22 10:10

cNoNim