Unity初心者です。
C#スクリプト側からMacOSのターミナルを立ち上げ、標準出力をそのままC#側へ返してあげたいのですが、
C#
1using System.Collections; 2using System.Collections.Generic; 3using System.Diagnostics; 4using UnityEngine; 5 6public class GameObject : MonoBehaviour 7{ 8 void Start() 9 { 10 Process process = new Process(); 11 process.StartInfo.FileName = "/Applications/Utilities/Terminal.app"; 12 process.Start(); 13 } 14}
この記述だときちんとTerminal.app
が立ち上がってくれるのですが、標準入力&出力を行うために、以下の用に書き足しを行いました。
C#
1void Start() 2 { 3 Process process = new Process(); 4 process.StartInfo.FileName = "/Applications/Utilities/Terminal.app"; 5 process.StartInfo.CreateNoWindow = true; 6 process.StartInfo.RedirectStandardInput = true; 7 process.StartInfo.RedirectStandardOutput = true; 8 process.StartInfo.UseShellExecute = false; 9 process.Start(); 10 process.StandardInput.WriteLine("ipconfig"); 11 process.StandardInput.Flush(); 12 process.StandardInput.Close(); 13 process.WaitForExit(); 14 }
すると以下の様なエラーがUnity側に吐き出されてしまいます。
bash
1Win32Exception: ApplicationName='/Applications/Utilities/Terminal.app', CommandLine='', CurrentDirectory='', Native error= Cannot find the specified file 2System.Diagnostics.Process.StartWithCreateProcess (System.Diagnostics.ProcessStartInfo startInfo) (at <0d3e94ab2a1c4d2a8582ccee7031f5c6>:0) 3System.Diagnostics.Process.Start () (at <0d3e94ab2a1c4d2a8582ccee7031f5c6>:0) 4(wrapper remoting-invoke-with-check) System.Diagnostics.Process.Start() 5GameObject.Start () (at Assets/Scripts/GameObject.cs:17)
何か原因をご存知の方がいらっしゃいましたらご教示頂けますと幸いです。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/09/05 10:07
2019/09/05 10:12
2019/09/05 10:55
2019/09/05 11:00
2019/09/06 02:58
2019/09/06 02:59
2019/09/06 03:02
2019/09/06 03:03