ProcessUtil.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. using System;
  2. using System.Diagnostics;
  3. using UnityEditor;
  4. using UnityEngine;
  5. namespace GFGEditor
  6. {
  7. public class ProcessUtil
  8. {
  9. public static void ExcuteBat(string targetDir, string fileName, string argument = null)
  10. {
  11. Process proc = null;
  12. try
  13. {
  14. targetDir = string.Format(@targetDir);//this is where mybatch.bat lies
  15. proc = new Process();
  16. proc.StartInfo.WorkingDirectory = targetDir;
  17. proc.StartInfo.FileName = fileName;
  18. if(!string.IsNullOrEmpty(argument))
  19. {
  20. proc.StartInfo.Arguments = string.Format(argument);
  21. }
  22. proc.StartInfo.CreateNoWindow = false;
  23. proc.Start();
  24. proc.WaitForExit();
  25. }
  26. catch (Exception ex)
  27. {
  28. UnityEngine.Debug.LogFormat("Exception Occurred :{0},{1}", ex.Message, ex.StackTrace.ToString());
  29. }
  30. }
  31. }
  32. }