Unity 执行命令行

using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
using UnityEditor;
using UnityEngine;

public static class M_ProcessExcuter {

    [MenuItem("cmd/excueDoc")]
    public static void ProcessExcuteDoc()
    {
        string path="Ping baidu.com";

        StartCmd(path);

    }


    private static void StartCmd(string Command)
    {
      
        //Command = Command.Trim().TrimEnd('&') + "&exit";//说明:不管命令是否成功均执行exit命令,否则当调用ReadToEnd()方法时,会处于假死状态
       // string output = null;
            Process p = new Process();//创建进程对象 
            p.StartInfo.FileName = @"C:WindowsSystem32cmd.exe";//设定需要执行的命令 

            //p.StartInfo.CreateNoWindow = false;//不创建窗口 
            // string comStr = comd1 + "&" + comd2 + "&" + comd3;
            p.StartInfo.UseShellExecute = true; //是否执行shell
            p.StartInfo.RedirectStandardInput = false;
            p.StartInfo.RedirectStandardOutput = false;
            p.StartInfo.Arguments = "/k "+ Command;// 单个命令
            p.Start();
            
            //p.StandardInput.WriteLine(Command);
           // output = p.StandardOutput.ReadToEnd();
            p.StandardInput.AutoFlush = true;
            p.StandardInput.Close();
            p.WaitForExit();//等待程序执行完退出进程
            p.Close();
    }

    private static void CmdExcute()
    {
        Process.Start(@"C:Windowssystem32cmd.exe","c:");
        Process.Start(@"C:Windowssystem32cmd.exe", "ping baidu.com");
    }

    private static void SimpleExcute()
    {
        Process.Start(@"C:Program Files (x86)GoogleChromeApplicationchrome.exe", "https://www.cnblogs.com/yangxiaohang");        
    }


}

  

原文地址:https://www.cnblogs.com/yangxiaohang/p/8617678.html