hch
2025-06-19 35f08360f1e07c7a8301f7b2031c0779e2998fb5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class SystemCMD
{
    /// <summary>
    /// 调用终端执行命令
    /// </summary>
    /// <param name="command"></param>
    /// <returns></returns>
    public static string RunCmd(string command)
    {
        System.Diagnostics.Process p = new System.Diagnostics.Process();
        p.StartInfo.FileName = "cmd.exe";           //确定程序名
        p.StartInfo.Arguments = "/c " + command;    //确定程式命令行
        p.StartInfo.UseShellExecute = false;        //Shell的使用
        p.StartInfo.RedirectStandardInput = true;   //重定向输入
        p.StartInfo.RedirectStandardOutput = true; //重定向输出
        p.StartInfo.RedirectStandardError = true;   //重定向输出错误
        p.StartInfo.CreateNoWindow = true;          //设置置不显示示窗口
        p.Start();
        p.WaitForExit();
        string err = p.StandardError.ReadToEnd();
        string standoutput = p.StandardOutput.ReadToEnd();
        if (string.IsNullOrEmpty(err))
        {
            return standoutput;
        }
        else
        {
            return err;        //输出出流取得命令行结果果
        }
    }
 
}