Skip to content

Instantly share code, notes, and snippets.

@lucasmeijer
Created March 15, 2015 21:03
Show Gist options
  • Save lucasmeijer/51634b6605709686f9de to your computer and use it in GitHub Desktop.
Save lucasmeijer/51634b6605709686f9de to your computer and use it in GitHub Desktop.
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
namespace Unity.Il2CPP.Builders
{
public class SimpleExecutable : BuiltProgram
{
private readonly string _path;
public SimpleExecutable(string path)
{
_path = path;
}
public override RunResult Run()
{
var p = new Process
{
StartInfo =
{
Arguments = "",
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardInput = true,
RedirectStandardError = true,
FileName = _path,
StandardOutputEncoding = Encoding.UTF8,
StandardErrorEncoding = Encoding.UTF8,
}
};
var stdout = new List<string>();
var stderr = new List<string>();
p.OutputDataReceived += (sender, args) =>
{
if (args.Data != null) stdout.Add(args.Data);
};
p.ErrorDataReceived += (sender, args) =>
{
if (args.Data != null) stderr.Add(args.Data);
};
p.Start();
p.BeginOutputReadLine();
p.BeginErrorReadLine();
p.WaitForExit();
p.CancelOutputRead();
p.CancelErrorRead();
return new RunResult() {ExitCode = p.ExitCode, StdOut = stdout.ToArray(), StdErr = stderr.ToArray()};
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment