Hi ! I am trying to run Ant from my console application. I don't want to use a batch file. I am having problems with my command and need some help. My build script is in D:\apps\serverapps And here is the command String cmd = new String; cmd = "cmd.exe" ; cmd = "/c" ; cmd = "cd d:\\apps\\serverapps"; cmd="ant"; I am getting the following error message: "The system cannot find the path specified". If I don't specify the fourth array element or fourth command then I dont get any error. But on specifying the fourth command I get error, be it "ant" or "cd" or "dir". Danish [ February 25, 2004: Message edited by: Danish Shaukat ]
The array passed to exec() should contain the command-line tokens of a single command, not a list of commands (i.e. "CD" and "ant"). You can't change the working directory using "CD" anyway, since it will be invoked in a seperate process. Check out the java.lang.Runtime documentation. There's a couple of exec() methods that take the working directory as an argument or you could probably get away with passing the full path of the build.xml file to ant if you used full (not local) paths in it.
By doing such a thing, you are breaking one of the design intentions of Ant - to remain platform independant. Why aren't you calling on the Ant APIs to start a build ? Those APIs were exposed for that exact reason.