Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Last active April 16, 2016 15:49
Show Gist options
  • Save tsubaki/6822293 to your computer and use it in GitHub Desktop.
Save tsubaki/6822293 to your computer and use it in GitHub Desktop.
Unityで別プロセスを実行し、ログを受け取る
using System.Text;
using UnityEditor;
using UnityEngine;
public class ExecuteShell
{
static readonly string argment = "hoge.sh";
static readonly int maxSize = 1048576;
[MenuItem("Edit/Execute %t")]
static void Execute ()
{
var p = new System.Diagnostics.Process ();
p.EnableRaisingEvents = true;
p.StartInfo.FileName = "sh";
p.StartInfo.Arguments = argment;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.Start ();
p.WaitForExit ();
var data = new byte[maxSize];
p.StandardOutput.BaseStream.Read(data, 0, maxSize);
var msg = Encoding.UTF8.GetString(data);
Debug.Log(msg);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment