views:

2783

answers:

3

Hi

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

A: 

How about <exec executable="start.exe"> ? Or 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)?

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

dpb
+5  A: 

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?

beny23
Hi, thank you. Pl read my additional comments, and pl suggest if I can achieve the same (additonal dos-prompt/window for each of my app server start) using cmd instead of start
thank you. The vendor's build.xml has input, output, etc. in the exec statement, and hence I can't use spawn.
A: 

Hi,

I am also facing the same issue. I have MKS Toolkit installed and it's directory containing "start.exe" is in path still I get the CreateProcess error.

The ANT project looks similar to this,

<project name="test-project" default="test-start">
<target name="test-start" >
    <echo message="basedir = ${basedir}"/>
    <exec dir="D:/Program Files/MKS Toolkit/mksnt/" executable="start" failonerror="true" >
      <arg line="notepad.exe" />
    </exec>
</target>

The output on running the project is,

D:\Test>ant -f build-test.xml
Buildfile: build-test.xml

test-start:
     [echo] basedir = D:\Test

BUILD FAILED
D:\Test\build-test.xml:4: E
xecute failed: java.io.IOException: Cannot run program "start" (in directory "D:
\Program Files\MKS Toolkit\mksnt"): CreateProcess error=2, The system cannot fin
d the file specified

Total time: 0 seconds

Thanks in advance.

K Shah