Unityからexeを実行して、標準出力を読み込む
表題の通りです。
using System.Diagnostics; using UnityEngine; public class Sample : MonoBehaviour { private Process proc; public void Handle() { this.proc = new Process(); this.proc.StartInfo.FileName = "exeのpath"; this.proc.StartInfo.Arguments = "exeの引数"; this.proc.StartInfo.WindowStyle = ProcessWindowStyle.Normal; this.proc.OutputDataReceived += this.OnRecieved; this.proc.StartInfo.UseShellExecute = false; this.proc.StartInfo.RedirectStandardError = true; this.proc.StartInfo.RedirectStandardOutput = true; this.proc.Start(); this.proc.BeginOutputReadLine(); } private void OnRecieved(object sender, DataReceivedEventArgs e) { UnityEngine.Debug.Log(e.Data); } private void OnApplicationQuit() { if (!this.proc.HasExited) { this.proc.CloseMainWindow(); } this.proc.Close(); this.proc = null; } }
OnRecievedはメインスレッド以外で呼ばれるので、SynchronizationContext等を組み合わせることが多い印象です。