Created
March 15, 2015 21:03
-
-
Save lucasmeijer/51634b6605709686f9de to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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