The really strange thing is that the virtual machine that launches the
dos command does indeed
spawn correctly as I can see its process complete. I've even debugged
it right to the very end.
So it seems that the grandparent process responsible for running the
ant java task has some strange connection
with the grandchild dos command window:
java.exe ---> ant-java (fork=true, spawn=false) ---> ant-
exec (spawn=true) ---> cmd.exe
alive
alive
dead!!! alive
On 27 Apr 2009, at 20:46, Ashley Williams wrote:
Didn't make any difference. I did however get the stack trace from
the ant java task vm and the only non daemon thread
dump looks like this:
Thread [main] (Suspended)
ProcessImpl.waitFor() line: not available [native method]
Execute.waitFor(Process) line: 551
Execute.execute() line: 482
Java.fork(String[]) line: 784
Java.executeJava(CommandlineJava) line: 211
Java.executeJava() line: 132
Java.execute() line: 105
NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line:
not available [native method]
NativeMethodAccessorImpl.invoke(Object, Object[]) line: not
available
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: not
available
Method.invoke(Object, Object...) line: not available
DispatchUtils.execute(Object) line: 106
Java(Task).perform() line: 348
Target.execute() line: 357
Target.performTasks() line: 385
Project.executeSortedTargets(Vector) line: 1337
Project.executeTarget(String) line: 1306
ProtoProject.antTest() line: 105
ProtoProject.main(String[]) line: 58
On 27 Apr 2009, at 20:13, Martin Gainty wrote:
in your programmatic call what happens if you put in a
execTask.setFailonerror(true);
execTask.setFailIfExecutionFails(true);
http://api.dpml.net/ant/1.7.0/org/apache/tools/ant/taskdefs/ExecTask.html#setFailIfExecutionFails(boolean)
before the execute()
public static void main(String[] args) throws IOException
{
// top level project
Project project = new Project();
project.setName("project");
project.init();
// project has a target child
Target target = new Target();
target.setName("target");
project.addTarget(target);
// target has an exec child
ExecTask execTask = new ExecTask();
execTask.setProject(project);
execTask.setExecutable("cmd.exe");
execTask.setSpawn(true);
execTask.setDir(new File("."));
addArg(execTask, "/c");
addArg(execTask, "start");
addArg(execTask, "test.bat");
execTask.setFailonerror(true);
execTask.setFailIfExecutionFails(true);
target.addTask(execTask);
target.execute();
}
?
Martin
______________________________________________
Disclaimer and Confidentiality/Verzicht und
Vertraulichkeitanmerkung / Note de déni et de confidentialité
This message is confidential. If you should not be the intended
receiver, then we ask politely to report. Each unauthorized
forwarding or manufacturing of a copy is inadmissible. This message
serves only for the exchange of information and has no legal
binding effect. Due to the easy manipulation of emails we cannot
take responsibility over the the contents.
Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene
Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede
unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig.
Diese Nachricht dient lediglich dem Austausch von Informationen und
entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten
Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den
Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes
pas le destinataire prévu, nous te demandons avec bonté que pour
satisfaire informez l'expéditeur. N'importe quelle diffusion non
autorisée ou la copie de ceci est interdite. Ce message sert à
l'information seulement et n'aura pas n'importe quel effet
légalement obligatoire. Étant donné que les email peuvent
facilement être sujets à la manipulation, nous ne pouvons accepter
aucune responsabilité pour le contenu fourni.
From: ashpub...@mac.com
To: user@ant.apache.org
Subject: Re: Calling ant programatically
Date: Mon, 27 Apr 2009 18:42:04 +0100
Ok here's a little more context.
It seems that the exec/spawn=true command works as expected when
called on its own directly from java.exe
but not from an intermediate ant java task, so:
1. GOOD... When I launch the cmd.exe from a programmatic ant exec
task, the exec task and java.exe both complete, and the dos window
remains until I close it ( I've left a large gap in the chain
description so it lines up with the next example):
java.exe ---
ant
-exec (spawn=true) ---> cmd.exe
(terminates before dos cmd.exe window is closed)
2. BAD... When I insert an programmatic ant java task, the exec task
appears to complete but the ant java task doesn't. Then when
I close the dos window the java.exe process completes also. This is
despite the ant-exec spawn attribute being true.
java.exe ---> ant-java (fork=true, spawn=false) ---> ant-
exec (spawn=true) ---> cmd.exe
(terminates only when dos cmd.exe window is closed)
I know it looks a little unusual to have the extra ant-java task in
there but it is necessary for my use-case and I don't have
the option to set spawn to true for it. Any ideas?
Many Thanks
- Ashley
On 24 Apr 2009, at 13:20, Ashley Williams wrote:
Hi,
I would like to know how to start a batch file in a new dos window
without blocking the java process and so naturally I
tried the following that does work:
<project name="project" default="target" basedir=".">
<target name="target">
<exec executable="cmd" spawn="true" dir="${basedir}">
<arg value="/c"/>
<arg value="start"/>
<arg value="test.bat"/>
</exec>
</target>
</project>
However I need to be able to do this from java and so I used the
following snippet of code that I thought would
represent the same functionality as the ant script:
public static void main(String[] args) throws IOException {
// top level project
Project project = new Project();
project.setName("project");
project.init();
// project has a target child
Target target = new Target();
target.setName("target");
project.addTarget(target);
// target has an exec child
ExecTask execTask = new ExecTask();
execTask.setProject(project);
target.addTask(execTask);
execTask.setExecutable("cmd.exe");
execTask.setSpawn(true);
execTask.setDir(new File("."));
addArg(execTask, "/c");
addArg(execTask, "start");
addArg(execTask, "test.bat");
target.execute();
}
However it doesn't matter whether or not I set true of false for
the
spawn property the java process blocks
every time until I close the dos window by hand. Is there something
else I need to do to more closely
replicate the ant script?
Cheers
- Ashley
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@ant.apache.org
For additional commands, e-mail: user-h...@ant.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@ant.apache.org
For additional commands, e-mail: user-h...@ant.apache.org
_________________________________________________________________
Rediscover Hotmail®: Get quick friend updates right in your inbox.
http://windowslive.com/RediscoverHotmail?ocid=TXT_TAGLM_WL_HM_Rediscover_Updates2_042009
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@ant.apache.org
For additional commands, e-mail: user-h...@ant.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@ant.apache.org
For additional commands, e-mail: user-h...@ant.apache.org