ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Weintraub <>
Subject exec on batch file causes build to hang
Date Fri, 14 Aug 2009 23:28:18 GMT
You need to read the section about the <exec> task for Windows users.
You cannot execute a Batch command directly. You have to call
command.exe and use the /c parameter.

The following is from the <exec> task's page:

Windows Users

The <exec> task delegates to Runtime.exec which in turn apparently
calls ::CreateProcess. It is the latter Win32 function that defines
the exact semantics of the call. In particular, if you do not put a
file extension on the executable, only ".EXE" files are looked for,
not ".COM", ".CMD" or other file types listed in the environment
variable PATHEXT. That is only used by the shell.

Note that .bat files cannot in general by executed directly. One
normally needs to execute the command shell executable cmd using the
/c switch.

<target name="help">
  <exec executable="cmd">
    <arg value="/c"/>
    <arg value="ant.bat"/>
    <arg value="-p"/>
Cygwin Users

On 8/14/09, Scott Stark <> wrote:
> I'm not sure if this is an Ant problem or a batch file problem, so I'll
> start here -- apologies if it's inappropriate.
> I'm using an Ant build file to execute a Windows XP batch file using the
> exec command. My target looks something like this:
>       <exec executable="${VCC_CBU_ICdir_root}${file.separator}IC_start.bat"
>                   dir="${VCC_CBU_ICdir_root}"
>                   failonerror="${failonerror}"
>                   failifexecutionfails="${failifexecutionfails}"
>                   spawn="true"
>                   >
>         </exec>
> The problem is, spawn="true" results in an error:
>       spawn does not allow attributes related to input, output, error,
> result
>       spawn also does not allow timeout
>       finally, spawn is not compatible with a nested I/O <redirector>,
>       C:\working\stop_restart.xml:78: You have used an attribute or nested
> element which is not compatible with spawn
> However, if I remove spawn="true", the control never gets returned to the
> Ant build file (the batch file starts up a java process that never actually
> completes unless the process is killed), so the build hangs and never
> completes.
> I've used this exact syntax on other batch files running similar java
> processes, and it works perfectly. I'm not sure what's causing this one to
> hang, and I don't understand the spawn error messages. Any thoughts?
> thanks,
> Scott

David Weintraub

David Weintraub

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message