You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by John Brush <jo...@ideartis.ch> on 2001/02/08 23:34:31 UTC
[PATCH] fix for process spawning
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: john.brush@ideartis.ch, Internet: www.ideartis.ch
--------------------------------------------------------
Re: [PATCH] fix for process spawning
Posted by Bill Burton <bi...@progress.com>.
Hello,
A number of people have asked for this kind of detached or background
starting of an executable. I wrote generic support for this but didn't
have it sufficiently tested before code freeze hit for the 1.3 release.
What I've implemented allows the <exec> task (and it's subclasses) to run
an executable detached in the background either redirecting the output to
a file or opening a new window. This is done in a platform-independent
manner (at least for Windows 9x/NT/2K and UNIX). The <exec> task supports
four new attributes and one modified one:
detach=true|false - if true, runs process detached in the background
output=file-name - modified so this works when detach=true
inwindow=true|false - if true, runs process detached in a new window.
On Windows OS's opens a new console window. On UNIX, can run
xterm,
CDE dtterm, KDE konsole or gnome-terminal (and I plan to add
screen).
The type of window and geometry can be selected by exporting
environment variables before running Ant.
windowtitle="title of new window" - Title to display in new window
when
the inwindow attribute is set to true.
usescript=true|false - When true, will always use the script launcher
causing the antRun script to be called to execute the command.
This
works even if Ant is running in a 1.3 JVM.
Something I may consider is writing new versions of Execute.runCommand
that will support detached with output or detached in a window. This will
make it easier for other tasks to use this functionality.
As some of my changes conflict with at least one recently posted patch,
I'll post a patch once things settle down with the 1.3 release. In the
meantime, if anyone has comments on this functionality, I'm open to any
input.
-Bill Burton
John Brush wrote:
>
> 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.
<snip/>