miduo_client/Assets/Scripts/Editor/Util/ProcessUtil.cs

66 lines
2.0 KiB
C#

using UnityEngine;
using UnityEditor;
using System.IO;
namespace GameEditor.Util
{
public static class ProcessUtil
{
//
public static void ProcessCommand(string dir, string com, bool isShowWindow = false)
{
ProcessCommand(dir, new string[] { com }, isShowWindow);
}
public static void ProcessCommand(string dir, string[] coms, bool isShowWindow = false)
{
System.Diagnostics.Process p = new System.Diagnostics.Process();
//设置要启动的应用程序
p.StartInfo.FileName = "cmd.exe";
//是否使用操作系统shell启动
p.StartInfo.UseShellExecute = false;
//接受来自调用程序的输入信息
p.StartInfo.RedirectStandardInput = false;
//输出信息
p.StartInfo.RedirectStandardOutput = false;
//输出错误
p.StartInfo.RedirectStandardError = false;
//不显示程序窗口
p.StartInfo.CreateNoWindow = !isShowWindow;
// 设置文件夹
p.StartInfo.WorkingDirectory = dir;
// 执行命令
for (int i = 0; i < coms.Length; i++)
{
p.StartInfo.Arguments = "/k " + coms[i] + "&exit";
//启动程序
p.Start();
//等待程序执行完退出进程
p.WaitForExit();
}
//p.StartInfo.Arguments = "/k exit";
////启动程序
//p.Start();
//等待程序执行完退出进程
//p.WaitForExit();
p.Close();
}
// 打开文本
public static void OpenText(string tPath)
{
if (!File.Exists(tPath))
{
EditorUtility.DisplayDialog("提示", "文件不存在", "确定");
return;
}
System.Diagnostics.Process.Start("notepad.exe", tPath); //用记事本
}
}
}