zoukankan      html  css  js  c++  java
  • 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");        
        }
    
    
    }
    

      

  • 相关阅读:
    python读写操作excel数据
    python读写操作excel数据小应用
    操作系统相关知识
    网络编程课堂笔记
    UDP简单初识+socketserver 模块实现服务端并发
    链接循环+模拟远程执行命令+实现大文件上传
    循环通信
    luogu P2761 软件补丁问题
    luogu P4016 负载平衡问题
    P3381 【模板】最小费用最大流(spfa板子)
  • 原文地址:https://www.cnblogs.com/yangxiaohang/p/8617678.html
Copyright © 2011-2022 走看看