You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Scott Stark <ss...@us.ibm.com> on 2009/08/14 21:25:07 UTC

exec on batch file causes build to hang

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

      BUILD FAILED
      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

Re: AW: exec on batch file causes build to hang

Posted by Scott Stark <ss...@us.ibm.com>.
Sascha Ernst wrote:

> Perhaps this helps....
       <exec executable="cmd"
         dir="${VCC_CBU_ICdir_root}">
          <arg line="/c start cmd /c
                     &quot;IC_start.bat&quot;" />
       </exec>

Wow, that's some crazy code there! :-) Well, it does open a new window, but
unfortunately the original build still doesn't complete in the first
window. Sigh... I'm going to go after the developer who wrote this crazy
java program. Thanks to everyone for your ideas.

Scott

AW: exec on batch file causes build to hang

Posted by Sascha Ernst <sa...@living-e.com>.
Hello,

Perhaps this helps....
       <exec executable="cmd"
         dir="${VCC_CBU_ICdir_root}">
          <arg line="/c start cmd /c
                     &quot;IC_start.bat&quot;" />
       </exec>

This opens a new window, starts your program in this windows and continues
With the build script.
If you change the 2nd /c to /k the buildscripts stops until your program stops and
the windows closes.

BUT: because of the non-existing coupling between the buildscript and the called
program, you cannot use failonerror and stuff like that (shure, you can use it,
but not to monitor/react on the exit code of your program)

The &quot;s are usefull, if you have more complex arg lines.
In your case they are not needed.

Feel free to fiddle around with more or less cmd and start commands....

Ein Gruss von der Saar

--
Sascha Ernst
Dipl. Inform.
Head of Software Quality Management


Telefon: + 49 (0)681 - 302 - 5133
Telefax: + 49 (0)681 - 302 - 5109
E-Mail: sascha.ernst@living-e.com
Website: http://www.living-e.com


Living-e AG 
Campus D3 2
66123 Saarbrücken


Vorstand: Guido Polko
Aufsichtsratsvorsitzender: Uwe Feuersenger
Amtsgericht: Mannheim, HRB 111323

Besuchen Sie uns auf dem 10. ÖV-Symposium am 20.08.2009, Stand 14, Ruhrfestspielhaus, Recklinghausen.



-----Ursprüngliche Nachricht-----
Von: Scott Stark [mailto:sstark@us.ibm.com] 
Gesendet: Dienstag, 18. August 2009 16:16
An: Ant Users List
Betreff: Re: exec on batch file causes build to hang


David Weintraub wrote:
>
> > Can you run the batch file outside of Ant from the command line without
> the
> > process hanging?
>

I've discovered that running "start IC_start.bat" from the command line
opens the process in a new window and returns control to the executing
window (on Windows XP). So this does what I want. However, when I try and
do this from an Ant task, I get this error:

BUILD FAILED
C:\working\informix\stop_restart.xml:98: Execute failed:
java.io.IOException: CreateProcess: start C:\VCC\IC_start.bat error=2

Any idea what "error=2" means, and how I can fix it?

Here's my task FYI:

      <exec executable="start"
                  failonerror="${failonerror}"
                  failifexecutionfails="${failifexecutionfails}"
                  dir="${VCC_CBU_ICdir_root}">
          <arg value="${VCC_CBU_ICdir_root}${file.separator}IC_start.bat"/>
        </exec>

thanks!

Scott

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: exec on batch file causes build to hang

Posted by Scott Stark <ss...@us.ibm.com>.
> Another possibility is to surround the <exec> task with the <waitfor>
task.
> The <waitfor> task will terminate the <exec> task after a certain period
of
> time. I don't know how well it works on Windows.

Nice idea, but:

BUILD FAILED
C:\working\informix\stop_restart.xml:95: waitfor doesn't support the nested
"exec" element.

Scott

Re: exec on batch file causes build to hang

Posted by Scott Stark <ss...@us.ibm.com>.
David Weintraub wrote:
>
> > Can you run the batch file outside of Ant from the command line without
> the
> > process hanging?
>

I've discovered that running "start IC_start.bat" from the command line
opens the process in a new window and returns control to the executing
window (on Windows XP). So this does what I want. However, when I try and
do this from an Ant task, I get this error:

BUILD FAILED
C:\working\informix\stop_restart.xml:98: Execute failed:
java.io.IOException: CreateProcess: start C:\VCC\IC_start.bat error=2

Any idea what "error=2" means, and how I can fix it?

Here's my task FYI:

      <exec executable="start"
                  failonerror="${failonerror}"
                  failifexecutionfails="${failifexecutionfails}"
                  dir="${VCC_CBU_ICdir_root}">
          <arg value="${VCC_CBU_ICdir_root}${file.separator}IC_start.bat"/>
        </exec>

thanks!

Scott

Re: exec on batch file causes build to hang

Posted by David Weintraub <qa...@gmail.com>.
On Mon, Aug 17, 2009 at 11:00 AM, Scott Stark <ss...@us.ibm.com> wrote:

>
> > Can you run the batch file outside of Ant from the command line without
> the
> > process hanging?
>
> Hi David, technically, yes. But the process (batch file) doesn't "hang"; it
> executes a java tool and holds that state ("running") until the process is
> terminated by another batch file. In other words, the java process is
> running correctly, but even within the batch file, control is not returned
> to the command line, which is why I was hoping to "spawn" it (which I can
> do with other batch/java processes). Unfortunately I didn't write the batch
> file or the java tool so I'm unclear what's happening.
>
> I might look into running it from the <java> task -- thanks for the tip.


Another possibility is to surround the <exec> task with the <waitfor> task.
The <waitfor> task will terminate the <exec> task after a certain period of
time. I don't know how well it works on Windows.


-- 
David Weintraub
qazwart@gmail.com

Re: exec on batch file causes build to hang

Posted by Scott Stark <ss...@us.ibm.com>.
> Can you run the batch file outside of Ant from the command line without
the
> process hanging?

Hi David, technically, yes. But the process (batch file) doesn't "hang"; it
executes a java tool and holds that state ("running") until the process is
terminated by another batch file. In other words, the java process is
running correctly, but even within the batch file, control is not returned
to the command line, which is why I was hoping to "spawn" it (which I can
do with other batch/java processes). Unfortunately I didn't write the batch
file or the java tool so I'm unclear what's happening.

I might look into running it from the <java> task -- thanks for the tip.

Scott

Re: exec on batch file causes build to hang

Posted by David Weintraub <qa...@gmail.com>.
Can you run the batch file outside of Ant from the command line without the
process hanging?

Do you have echo turned on or off in the Batch file? I don't use a Windows
system, so I don't know if the commands echo if echo is on. However, you
sound like you're pretty sure that its the Java task that's dying or
hanging.  Maybe you could run the Java profiler (-Xprof) option? It could be
a memory problem with Ant not giving enough memory to the Java process.
Remember that Ant, exec, and your Java process are all running in the same
memory footprint. Ant, by default, only runs under 64mb. You can use the
ANT_OPTS environment variable to set Ant to run with more memory
(ANT_OPTS=-Xmx512m for example). See if that helps.

I know that Windows doesn't seem to support "spawn" in the <exec> task. Have
you tried the <java> task if you're just running a Java program anyway? You
might have more luck with that.

On Fri, Aug 14, 2009 at 9:11 PM, Scott Stark <ss...@us.ibm.com> wrote:

> Hi David, thank you kindly for the pointer about running batch files on
> Windows. However, I get the same results when running my build file from the
> command line: the batch file executes (and starts the java process), but
> never returns control to the build file, so I have to hit control-C to exit
> the batch file.
>
> <exec executable="cmd"
> failonerror="${failonerror}"
> failifexecutionfails="${failifexecutionfails}"
>
> dir="${VCC_CBU_ICdir_root}">
> <arg value="/c"/>
> <arg value="${VCC_CBU_ICdir_root}${file.separator}IC_start.bat"/>
> </exec>
>
>
> Does this sound like something is going on in the batch file? Perhaps it's
> looping or something...
>
> Scott
>
>
> [image: Inactive hide details for David Weintraub <qa...@gmail.com>]David
> Weintraub <qa...@gmail.com>
>
>
>
> > 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.
>
>
>
>
>
>
>


-- 
David Weintraub
qazwart@gmail.com

Articles on Ant tips & tricks!!!

Posted by Bob Aiello <ra...@acm.org>.
Hi Everyone,

I am looking for people who are interested in sharing best practices
for using Ant, Maven and Make. The articles will appear in CM Basics
(www.cmcrossroads.com).

We have 60,000+ readers with lots of existing articles and forums on
build engineering.

Please contact me directly if you are interesting in submitting an article!

Bob Aiello
raiello@acm.org
Editor in Chief
CM Crossroads
http://www.linkedin.com/in/BobAiello



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: exec on batch file causes build to hang

Posted by Scott Stark <ss...@us.ibm.com>.
Hi David, thank you kindly for the pointer about running batch files on
Windows. However, I get the same results when running my build file from
the command line: the batch file executes (and starts the java process),
but never returns control to the build file, so I have to hit control-C to
exit the batch file.

<exec executable="cmd"
                  failonerror="${failonerror}"
                  failifexecutionfails="${failifexecutionfails}"
                  dir="${VCC_CBU_ICdir_root}">
          <arg value="/c"/>
          <arg value="${VCC_CBU_ICdir_root}${file.separator}IC_start.bat"/>
</exec>


Does this sound like something is going on in the batch file? Perhaps it's
looping or something...

Scott






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






exec on batch file causes build to hang

Posted by David Weintraub <qa...@gmail.com>.
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"/>
  </exec>
</target>
Cygwin Users



On 8/14/09, Scott Stark <ss...@us.ibm.com> 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>,
>
>       BUILD FAILED
>       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
qazwart@gmail.com


-- 
David Weintraub
qazwart@gmail.com

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org