Last active
April 16, 2016 15:49
-
-
Save tsubaki/6822293 to your computer and use it in GitHub Desktop.
Unityで別プロセスを実行し、ログを受け取る
This file contains 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.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