mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-19 20:39:01 +00:00
48 lines
1.8 KiB
C#
48 lines
1.8 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;
|
|
using (var xProcess = Process.Start(xProcessStartInfo))
|
|
{
|
|
if (!xProcess.WaitForExit(30 * 1000) || 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;
|
|
}
|
|
}
|
|
}
|