Cosmos/source2/Build/Cosmos.Build.MSBuild/BaseToolTask.cs
mterwoord_cp 18b6e818c0
2010-07-30 17:50:00 +00:00

50 lines
1.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Build.Utilities;
using System.Diagnostics;
namespace Cosmos.Build.MSBuild
{
public abstract class BaseToolTask: Task
{
protected bool ExecuteTool(string workingDir, string filename, string arguments, string name)
{
var xProcessStartInfo = new ProcessStartInfo();
xProcessStartInfo.WorkingDirectory = workingDir;
xProcessStartInfo.FileName = filename;
xProcessStartInfo.Arguments = arguments;
xProcessStartInfo.UseShellExecute = false;
xProcessStartInfo.RedirectStandardOutput = true;
xProcessStartInfo.RedirectStandardError = true;
xProcessStartInfo.CreateNoWindow = true;
using (var xProcess = Process.Start(xProcessStartInfo))
{
xProcess.WaitForExit();
if (xProcess.ExitCode != 0)
{
if (!xProcess.HasExited)
{
xProcess.Kill();
Log.LogError("{0} timed out.", name);
}
else
{
Log.LogError("Error occurred while invoking {0}", name);
}
while (!xProcess.StandardOutput.EndOfStream)
{
Log.LogMessage("{0} output: {1}", name, xProcess.StandardOutput.ReadLine());
}
while (!xProcess.StandardError.EndOfStream)
{
Log.LogMessage("{0} error: {1}", name, xProcess.StandardError.ReadLine());
}
return false;
}
}
return true;
}
}
}