熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

c#程序中如何執行 dos命令

2013-11-13 09:55:22  來源: .NET編程 

  C#中執行Dos命令 C# 本來封裝了很多 類似於Dos命令的東西可是開發需要用它來執行 cmdtexe

  static void Main(string[] args)

  { commandstartcmd(pingcommandcmdPross(ping }

  public static string cmdPross(string command string argument)

  { string output = try { Process cmd = new Process()

  cmdStartInfoFileName = commandcmdStartInfoArguments = argument

  cmdStartInfoUseShellExecute = false

  cmdStartInfoRedirectStandardInput = truecmdStartInfoRedirectStandardOutput = true

  cmdStartInfoCreateNoWindow = truecmdStartInfoWindowStyle = ProcessWindowStyleHidden

  cmdStart()

  output = cmdStandardOutputReadToEnd()ConsoleWriteLine(output)cmdWaitForExit()cmdClose()} catch (Exception e)

  { ConsoleWriteLine(e)} return output}


From:http://tw.wingwit.com/Article/program/net/201311/11984.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.