ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ashley Williams <ashpub...@mac.com>
Subject Calling ant programatically
Date Fri, 24 Apr 2009 12:20:48 GMT
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-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message