zoukankan      html  css  js  c++  java
  • Run dos command IN C#

            /// <summary>
            
    /// A method used to run a dos command hiddenly.
            
    /// </summary>
            
    /// <param name="dosCommand"></param>
            
    /// <param name="outtime"></param>
            
    /// <returns></returns>
            public static string Execute(string dosCommand, int outtime)
            {
                
    string output = "";
                
    if (dosCommand != null && dosCommand != "")
                {
                    Process process 
    = new Process();//create process object
                    ProcessStartInfo startinfo = new ProcessStartInfo();
                    startinfo.FileName 
    = "cmd.exe";//
                    
    //bellow is the setting to hidden the console window
                    startinfo.Arguments = "/c" + dosCommand;
                    startinfo.UseShellExecute 
    = false;
                    startinfo.RedirectStandardInput 
    = false;
                    startinfo.RedirectStandardOutput 
    = true;
                    startinfo.CreateNoWindow 
    = true;
                    process.StartInfo 
    = startinfo;

                    
    try
                    {
                        
    if (process.Start())
                        {
                            
    if (outtime == 0)
                            { process.WaitForExit(); }
                            
    else
                            { process.WaitForExit(outtime); }
                            output 
    = process.StandardOutput.ReadToEnd();
                        }
                    }
                    
    catch (SqlException e)
                    {
                        
    throw e;
                    }
                    
    catch (Exception e)
                    {
                        
    throw e;
                    }
                    
    finally
                    {
                        
    if (process != null)
                        { process.Close(); }
                    }
                }
                
    return output;
            } 
  • 相关阅读:
    swift锁屏播放,音乐进度更新,专辑,歌手名显示
    swift Dictionary 字典
    Swift中的集合类型
    Swift String 一些常用方法
    Swift自定义Class实现Hashable
    二元最近的共同祖先问题(O(n) time 而且,只有一次遍历,O(1) Space (它不考虑函数调用栈空间))
    BZOJ1579 USACO 2009 Feb Gold 3.Revamping Trails Solution
    [DEEP LEARNING An MIT Press book in preparation]Linear algebra
    POJ--2391--Ombrophobic Bovines【分割点+Floyd+Dinic优化+二分法答案】最大网络流量
    c#-RTF文本编辑器
  • 原文地址:https://www.cnblogs.com/RobotTech/p/1162215.html
Copyright © 2011-2022 走看看