From 694b6a391cda040e66e35ac2a3ac56e0f956d99f Mon Sep 17 00:00:00 2001 From: Peter Donald Date: Fri, 21 Dec 2001 13:19:39 +0000 Subject: [PATCH] Converted the old WinNTCommandLauncher to new setup. There is no need to extend ProxyCommandLauncher as it did not offer any benefit (because the 2 arg version of Runtime.exec was always called) git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270281 13f79535-47bb-0310-9956-ffa450edef68 --- .../exec/launchers/WinNTCommandLauncher.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/launchers/WinNTCommandLauncher.java diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/launchers/WinNTCommandLauncher.java b/proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/launchers/WinNTCommandLauncher.java new file mode 100644 index 000000000..cb012b97e --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/launchers/WinNTCommandLauncher.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) The Apache Software Foundation. All rights reserved. + * + * This software is published under the terms of the Apache Software License + * version 1.1, a copy of which has been included with this distribution in + * the LICENSE.txt file. + */ +package org.apache.myrmidon.framework.exec.launchers; + +import java.io.IOException; +import org.apache.myrmidon.api.TaskException; +import org.apache.myrmidon.framework.exec.CommandLauncher; +import org.apache.myrmidon.framework.exec.ExecMetaData; + +/** + * A command launcher for Windows 2000/NT that uses 'cmd.exe' when launching + * commands in directories other than the current working directory. + * + * @author Peter Donald + * @author Thomas Haas + * @version $Revision$ $Date$ + */ +public class WinNTCommandLauncher + implements CommandLauncher +{ + /** + * Launches the given command in a new process using cmd.exe to + * set the working directory. + */ + public Process exec( final ExecMetaData metaData ) + throws IOException, TaskException + { + // Use cmd.exe to change to the specified directory before running + // the command + final String[] prefix = new String[ 6 ]; + prefix[ 0 ] = "cmd"; + prefix[ 1 ] = "/c"; + prefix[ 2 ] = "cd"; + prefix[ 3 ] = "/d"; + prefix[ 4 ] = metaData.getWorkingDirectory().getCanonicalPath(); + prefix[ 5 ] = "&&"; + + final ExecMetaData newMetaData = ExecUtil.prepend( metaData, prefix ); + return Runtime.getRuntime(). + exec( newMetaData.getCommand(), newMetaData.getEnvironment() ); + } +}