WEB开发网
开发学院软件开发VC 在win form工程中怎麽樣調用xcopy系統命令 阅读

在win form工程中怎麽樣調用xcopy系統命令

 2008-10-25 19:26:53 来源:WEB开发网   
核心提示:private string RunCommand(string cmd) { string res = String.Empty; string error = String.Empty; Process p = new Process(); StreamWriter sw; StreamReader sr; //S

private  string  RunCommand(string  cmd)  
       {  
          string  res    =  String.Empty;  
          string  error  =  String.Empty;  
          Process  p     =  new  Process();  
          StreamWriter  sw;  
          StreamReader  sr;  
          //StreamReader  err;  
           
          ProcessStartInfo  psI        =  new  ProcessStartInfo("cmd");  
          psI.UseShellExecute         =  false;  
          psI.RedirectStandardInput   =  true;  
          psI.RedirectStandardOutput  =  true;  
          psI.RedirectStandardError   =  true;  
          psI.CreateNoWindow          =  true;  
          p.StartInfo                 =  psI;  
  
          try  
          {  
             p.Start();  
             sw   =  p.StandardInput;  
             sr   =  p.StandardOutput;  
             //err  =  p.StandardError;  
  
             sw.AutoFlush  =  true;  
             sw.WriteLine(cmd);  
             sw.Close();  
             //error         =  err.ReadToEnd();  
             res           =  sr.ReadToEnd();  
              
             //err.Close();  
             sr.Close();  
             p.Close();  
          }  
          catch(Exception  e)  
          {  
             MessageBox.Show("Error  when  run  command:  "  +  cmd  +  "n"  +  e.Message  +  "n");  
             return  "";  
          }  
           
          if(error.Length  !=  0)  
          {  
             MessageBox.Show("Error  when  run  command:  "  +  cmd  +  "n"  +  error  +  "n");  
             return  "";  
          }  
          return  res;  
       }

Tags:win form 工程

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接