ShellHelper.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System.Diagnostics;
  2. using UnityEngine;
  3. namespace ETEditor {
  4. public static class ShellHelper {
  5. public static void Bash(this string cmd, string workingDirectory, bool startTerminal = false) {
  6. ProcessStartInfo startInfo = new ProcessStartInfo("/bin/bash") {
  7. WorkingDirectory = workingDirectory,
  8. UseShellExecute = false,
  9. RedirectStandardInput = true,
  10. RedirectStandardOutput = true
  11. };
  12. Process process = new Process {
  13. StartInfo = startInfo
  14. };
  15. process.Start();
  16. string code = "";
  17. if(startTerminal) {
  18. code = "osascript -e 'tell application \"Terminal\" to do script \"" +
  19. "" + cmd + "\" in selected tab of the front window'";
  20. } else {
  21. code = cmd;
  22. }
  23. process.StandardInput.WriteLine(code);
  24. process.StandardInput.WriteLine("exit");
  25. process.StandardInput.Flush();
  26. string line = process.StandardOutput.ReadLine();
  27. while(line != null) {
  28. UnityEngine.Debug.Log("line:" + line);
  29. line = process.StandardOutput.ReadLine();
  30. }
  31. process.WaitForExit();
  32. }
  33. }
  34. }