I am using Ant to do some development with weblogic server, and I ran into
some problems trying to get it to return after spawning a new process/window
at the command line (Windows 2000). A quick scan of this mail list showed me
I was not the first person to run into this problem. Unfortunatly I don't
have the time to research this in more detail (got a deadline end of Feb.),
but the attached patch has at least solved my problem. Perhaps it can serve
as a basis for something along these lines in a future release.
Here's what my target now looks like, with the addition of the
"waitforcompletion" attribute:
<target name="wl.start" depends="wl.deploy">
<exec executable="c:\winnt\system32\cmd.exe"
failonerror="yes"
waitforcompletion="no">
<arg line="/c start cmd /c "cd ${weblogic} & startweblogic
""/>
</exec>
</target>
John
--- C:\ant-src2\src\main\org\apache\tools\ant\taskdefs\ExecTask.java Tue Oct
24 07:45:26 2000
+++ ExecTask.java Wed Feb 07 11:04:10 2001
@@ -74,6 +74,7 @@
private File out;
private File dir;
protected boolean failOnError = false;
+ private boolean waitforcompletion = true;
private Integer timeout = null;
private Environment env = new Environment();
protected Commandline cmdl = new Commandline();
@@ -132,6 +133,13 @@
}
/**
+ * Allow process spawning
+ */
+ public void setWaitforcompletion(boolean wait) {
+ waitforcompletion = wait;
+ }
+
+ /**
* Add a nested env element - an environment variable.
*/
public void addEnv(Environment.Variable var) {
@@ -191,6 +199,7 @@
Execute exe = new Execute(createHandler(), createWatchdog());
exe.setAntRun(project);
exe.setWorkingDirectory(dir);
+ exe.setWaitforcompletion(waitforcompletion);
String[] environment = env.getVariables();
if (environment != null) {
for (int i=0; i<environment.length; i++) {
--- C:\ant-src2\src\main\org\apache\tools\ant\taskdefs\Execute.java Tue Oct
24 07:45:26 2000
+++ Execute.java Wed Feb 07 13:36:54 2001
@@ -84,6 +84,7 @@
private ExecuteWatchdog watchdog;
private File workingDirectory = null;
private Project project = null;
+ private boolean waitforcompletion = true;
private static String antWorkingDirectory =
System.getProperty("user.dir");
private static CommandLauncher launcher = createCommandLauncher();
@@ -170,6 +171,9 @@
this.watchdog = watchdog;
}
+ public void setWaitforcompletion(boolean wait) {
+ waitforcompletion = wait;
+ }
/**
* Returns the commandline used to create a subprocess.
@@ -245,6 +249,12 @@
*/
public int execute() throws IOException {
final Process process = launcher.exec(project, getCommandline(),
getEnvironment(), workingDirectory);
+
+ // If the user is spawning a seperate process --> don't try to
redirect the streams
+ // and don't wait for the exit status
+ if ( !waitforcompletion )
+ return 0;
+
try {
streamHandler.setProcessInputStream(process.getOutputStream());
streamHandler.setProcessOutputStream(process.getInputStream());
--------------------------------------------------------
John Brush, Ideartis Consulting
Mobile 079 235 17 56, tel 01 420 16 94, fax 01 420 16 93
Post: Horneggstr. 9, CH-8008 Z�rich
Office Technopark: Technoparkstrasse 1, CH-8005 Z�rich
Email: [EMAIL PROTECTED], Internet: www.ideartis.ch
--------------------------------------------------------