asp.net 调用外部应用程序

来源:互联网 发布:网络app软件能加盟吗 编辑:程序博客网 时间:2024/04/30 12:38
 public string ExeCommand(string commandText)
    
{
        Process p 
= new Process();
        p.StartInfo.FileName 
= "cmd.exe"//换成你要执行的
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.RedirectStandardInput 
= true;
        p.StartInfo.RedirectStandardOutput 
= true;
        p.StartInfo.RedirectStandardError 
= true;
        p.StartInfo.CreateNoWindow 
= true;
        
string strOutput = null;
        
try
        
{
            p.Start();
            p.StandardInput.WriteLine(commandText);
            p.StandardInput.WriteLine(
"exit");
            strOutput 
= p.StandardOutput.ReadToEnd();
            p.WaitForExit();
            p.Close();
        }

        
catch (Exception e)
        
{
            strOutput 
= e.Message;
        }

        
return strOutput;
    }


 
原创粉丝点击