成人午夜激情影院,小视频免费在线观看,国产精品夜夜嗨,欧美日韩精品一区二区在线播放

如何在ASP.NET程序里面執(zhí)行DOS命令

2010-08-28 10:53:37來源:西部e網(wǎng)作者:

  /// <summary>
  /// 執(zhí)行DOS命令,返回DOS命令的輸出
  /// </summary>
  /// <param name="dosCommand">dos命令</param>
  /// <param name="milliseconds">等待命令執(zhí)行的時(shí)間(單位:毫秒),如果設(shè)定為0,則無限等待</param>
  /// <returns>返回輸出,如果發(fā)生異常,返回空字符串</returns>
  public static string ExecuteDos(string dosCommand, int milliseconds)
  {

   string output = ""; //輸出字符串
   if (dosCommand != null && dosCommand != "")
   {
    Process process = new Process(); //創(chuàng)建進(jìn)程對象
    ProcessStartInfo startInfo = new ProcessStartInfo();
    startInfo.FileName = "cmd.exe"; //設(shè)定需要執(zhí)行的命令
    startInfo.Arguments = "/C " + dosCommand; //設(shè)定參數(shù),其中的“/C”表示執(zhí)行完命令后馬上退出
    startInfo.UseShellExecute = false; //不使用系統(tǒng)外殼程序啟動
    startInfo.RedirectStandardInput = false; //不重定向輸入
    startInfo.RedirectStandardOutput = true; //重定向輸出
    startInfo.CreateNoWindow = true; //不創(chuàng)建窗口
    process.StartInfo = startInfo;

    try
    {
     if (process.Start()) //開始進(jìn)程
     {
      if (milliseconds == 0)
       process.WaitForExit(); //這里無限等待進(jìn)程結(jié)束
      else
       process.WaitForExit(milliseconds); //這里等待進(jìn)程結(jié)束,等待時(shí)間為指定的毫秒
      output = process.StandardOutput.ReadToEnd();//讀取進(jìn)程的輸出
     }
    }
    catch
    {
    }
    finally
    {
     if (process != null)
      process.Close();
    }
   }

   return output;

  }

關(guān)鍵詞:ASP.NET

贊助商鏈接:

主站蜘蛛池模板: 吴江市| 盐池县| 婺源县| 余江县| 云阳县| 兰溪市| 平湖市| 寿宁县| 寿阳县| 洛阳市| 桐柏县| 兰溪市| 读书| 枝江市| 哈巴河县| 固始县| 民乐县| 穆棱市| 遂平县| 武宣县| 筠连县| 大足县| 清新县| 蓝田县| 康平县| 阿拉尔市| 崇信县| 芦溪县| 宁明县| 淮南市| 固安县| 清涧县| 佛教| 武定县| 马山县| 黔西县| 沈阳市| 松溪县| 湖州市| 营山县| 黑水县|