2 // Exec.cs: Task that executes commands.
5 // Marek Sieradzki (marek.sieradzki@gmail.com)
7 // (C) 2005 Marek Sieradzki
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Collections;
32 using System.Collections.Specialized;
33 using System.Diagnostics;
36 using System.Threading;
37 using Microsoft.Build.Framework;
38 using Microsoft.Build.Utilities;
40 namespace Microsoft.Build.Tasks {
41 public class Exec : ToolTaskExtension {
46 string stdErrEncoding;
47 string stdOutEncoding;
48 string workingDirectory;
55 ignoreExitCode = false;
58 // FIXME: what does that method do?
60 protected internal override void AddCommandLineCommands (CommandLineBuilderExtension commandLine)
62 base.AddCommandLineCommands (commandLine);
65 /*public override bool Execute ()
67 StringCollection temporaryOutputs = new StringCollection ();
69 string[] commandTable = command.Split (null, 2);
70 string filename = commandTable [0];
71 string arguments = "";
72 if (commandTable.Length == 2)
73 arguments = commandTable [1];
75 if (workingDirectory != null)
76 process.StartInfo.WorkingDirectory = workingDirectory;
77 process.StartInfo.FileName = filename;
78 process.StartInfo.Arguments = arguments;
79 process.StartInfo.RedirectStandardOutput = true;
80 process.StartInfo.RedirectStandardError = true;
81 process.StartInfo.UseShellExecute = false;
85 process.WaitForExit ();
87 //exitCode = process.ExitCode;
88 while ((line = process.StandardOutput.ReadLine ()) != null)
89 temporaryOutputs.Add (line);
90 outputs = new ITaskItem [temporaryOutputs.Count];
92 foreach (string s in temporaryOutputs)
93 outputs [i++] = new TaskItem (s);
95 catch (Exception ex) {
96 Log.LogErrorFromException (ex);
100 if (exitCode != 0 && ignoreExitCode == false)
107 protected override int ExecuteTool (string pathToTool,
108 string responseFileCommands,
109 string commandLineCommands)
111 return base.ExecuteTool (GenerateFullPathToTool (), String.Empty, String.Empty);
115 protected override string GenerateFullPathToTool ()
121 protected override string GetWorkingDirectory ()
123 return Environment.CurrentDirectory;
127 protected override bool HandleTaskExecutionErrors ()
133 protected override void LogPathToTool (string toolName,
139 protected override void LogToolCommand (string message)
144 protected override bool ValidateParameters ()
150 public string Command {
151 get { return command; }
152 set { command = value; }
155 public bool IgnoreExitCode {
156 get { return ignoreExitCode; }
157 set { ignoreExitCode = value; }
161 public ITaskItem[] Outputs {
162 get { return outputs; }
163 set { outputs = value; }
166 protected override Encoding StandardErrorEncoding {
167 get { return Console.Error.Encoding; }
170 protected override MessageImportance StandardErrorLoggingImportance {
171 get { return base.StandardErrorLoggingImportance; }
174 protected override Encoding StandardOutputEncoding {
175 get { return Console.Out.Encoding; }
178 protected override MessageImportance StandardOutputLoggingImportance {
179 get { return base.StandardOutputLoggingImportance; }
184 public string StdOutEncoding {
185 get { return stdOutEncoding; }
186 set { stdOutEncoding = value; }
191 public string StdErrEncoding {
192 get { return stdErrEncoding; }
193 set { stdErrEncoding = value; }
197 protected override string ToolName {
198 get { return String.Empty; }
201 public string WorkingDirectory {
202 get { return workingDirectory; }
203 set { workingDirectory = value; }