mirror of
https://github.com/game-ci/unity-builder.git
synced 2025-07-04 12:25:19 -04:00
Add system extension for Process
This commit is contained in:
parent
e53dcf13e3
commit
328b0d8ac0
3
action/default-build-script/Assets/Editor/System.meta
Normal file
3
action/default-build-script/Assets/Editor/System.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b5da3bd7e18c43d79243410166c8dc9a
|
||||
timeCreated: 1587493708
|
@ -0,0 +1,42 @@
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
|
||||
public static class ProcessExtensions
|
||||
{
|
||||
// Execute an application or binary with given arguments
|
||||
//
|
||||
// See: https://stackoverflow.com/questions/4291912/process-start-how-to-get-the-output
|
||||
public static int Run(this Process process, string application,
|
||||
string arguments, string workingDirectory, out string output,
|
||||
out string errors)
|
||||
{
|
||||
// Configure how to run the application
|
||||
process.StartInfo = new ProcessStartInfo {
|
||||
CreateNoWindow = true,
|
||||
UseShellExecute = false,
|
||||
RedirectStandardError = true,
|
||||
RedirectStandardOutput = true,
|
||||
FileName = application,
|
||||
Arguments = arguments,
|
||||
WorkingDirectory = workingDirectory
|
||||
};
|
||||
|
||||
// Read the output
|
||||
var outputBuilder = new StringBuilder();
|
||||
var errorsBuilder = new StringBuilder();
|
||||
process.OutputDataReceived += (_, args) => outputBuilder.AppendLine(args.Data);
|
||||
process.ErrorDataReceived += (_, args) => errorsBuilder.AppendLine(args.Data);
|
||||
|
||||
// Run the application and wait for it to complete
|
||||
process.Start();
|
||||
process.BeginOutputReadLine();
|
||||
process.BeginErrorReadLine();
|
||||
process.WaitForExit();
|
||||
|
||||
// Format the output
|
||||
output = outputBuilder.ToString().TrimEnd();
|
||||
errors = errorsBuilder.ToString().TrimEnd();
|
||||
|
||||
return process.ExitCode;
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 29c1880a390c4af7be821b7877602815
|
||||
timeCreated: 1587494270
|
Loading…
Reference in New Issue
Block a user