やりたいこと
Unityで作成したEXEから指定のBatを起動したいです。
問題点
Unityでスタンドアロン版のExeを作成して起動するとエラーになる
UnityEditorのメニューバーからはエラーなく実行できます。
何が問題なんでしょうか
Error
1[ERROR]エラー:The Process object must have the UseShellExecute property set to false in order to redirect IO streams.
作成コード
C#
1 //batFilePath=.../_Data/StreamingAssets/callText.bat 2 private static void TEST(string batFilePath) 3 { 4 5 Debug.LogError("[TEST] Start"); 6 7 try 8 { 9 var startInfo = new System.Diagnostics.ProcessStartInfo() 10 { 11 FileName = batFilePath, 12 UseShellExecute = true, 13 ErrorDialog = true, 14 RedirectStandardOutput = true, 15 RedirectStandardError = true, 16 Verb = "RunAs", 17 }; 18 19 using (var process = System.Diagnostics.Process.Start(startInfo)) 20 { 21 var so = process.StandardOutput.ReadToEnd(); 22 var se = process.StandardError.ReadToEnd(); 23 24 process.WaitForExit(); 25 26 Debug.LogError("so" + so); 27 Debug.LogError("[TEST] ------"); 28 Debug.LogError("se" + se); 29 } 30 } 31 catch (Exception ex) 32 { 33 Debug.LogError("エラー:" + ex.Message); 34 } 35 36 Debug.LogError("[TEST] Exit"); 37 }
Batファイル
1 2@echo off 3call notepad.exe 4 5pause