亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

c#執(zhí)行外部命令示例分享

 更新時間:2013年12月26日 10:34:08   作者:  
c#執(zhí)行外部命令示例分享,大家參考使用吧

復制代碼 代碼如下:

String Command = @"python test.py";
String Output = Execute.run(Command);
Console.WriteLine(Output);

復制代碼 代碼如下:

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

//using before change the namespace
namespace test.utility
{
    class Execute
    {
        public static String run(String Command)
        {
            String Output = null;

            if (Command != null && !Command.Equals(""))
            {
                Process process = new Process();
                ProcessStartInfo processStartInfo = new ProcessStartInfo();
                processStartInfo.FileName = "cmd.exe";
                //no create the cmd windows
                processStartInfo.CreateNoWindow = true;
                processStartInfo.RedirectStandardInput = true;
                processStartInfo.RedirectStandardOutput = true;
                processStartInfo.RedirectStandardError = true;
                processStartInfo.UseShellExecute = false;

                process.StartInfo = processStartInfo;

                try
                {
                    process.Start();
                    process.StandardInput.WriteLine(Command);
                    process.StandardInput.WriteLine("exit");
                    process.WaitForExit(30 * 1000);
                    Output = process.StandardOutput.ReadToEnd();
                }
                catch (Exception e)
                {
                    process.Close();
                    return e.ToString();
                }
                finally
                {
                    process.Close();
                }
            }

            return ContextFilter(Output);
        }

        public static String ContextFilter(String Output)
        {
            Regex regex_end = new Regex("^[^^]*#end");
            Match match = regex_end.Match(Output);
            Regex regex_begin = new Regex("^[^^]*?#begin\r\n");
            String result = regex_begin.Replace(match.Value, "");
            Regex regex_tar = new Regex("\r\n#end$");
            result = regex_tar.Replace(result,"");
            return result;
        }
    }
}

相關文章

  • Unity代碼實現序列幀動畫播放器

    Unity代碼實現序列幀動畫播放器

    這篇文章主要為大家詳細介紹了Unity代碼實現序列幀動畫播放器,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-02-02
  • 深入分析C# 線程同步

    深入分析C# 線程同步

    這篇文章主要介紹了C# 線程同步的的相關資料,文中講解非常細致,代碼幫助大家更好的理解和學習,感興趣的朋友可以了解下
    2020-06-06
  • C# WinForm-Timer控件的使用

    C# WinForm-Timer控件的使用

    這篇文章主要介紹了C# WinForm-Timer控件的使用,幫助大家更好的理解和學習c# winform,感興趣的朋友可以了解下
    2020-11-11
  • C#固定大小緩沖區(qū)及使用指針復制數據詳解

    C#固定大小緩沖區(qū)及使用指針復制數據詳解

    這篇文章主要為大家介紹了C#固定大小緩沖區(qū)及使用指針復制數據詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-12-12
  • C#調用百度翻譯實現翻譯HALCON的示例

    C#調用百度翻譯實現翻譯HALCON的示例

    HALCON示例程序的描述部分一直是英文的,看起來很不方便。本文就使用百度翻譯實現翻譯HALCON,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-06-06
  • C#實現UDP打洞的示例代碼

    C#實現UDP打洞的示例代碼

    這篇文章主要為大家詳細介紹了C#中實現UDP打洞的相關知識,文中的示例代碼簡潔易懂,具有一定的借鑒價值,有需要的小伙伴可以參考一下
    2024-01-01
  • 詳解ASP.NET中Identity的身份驗證代碼

    詳解ASP.NET中Identity的身份驗證代碼

    這篇文章主要介紹了ASP.NET Identity 的“多重”身份驗證代碼,以及實現的原理講解,需要的朋友參考一下。
    2017-12-12
  • 直接在線預覽Word、Excel、TXT文件之ASP.NET

    直接在線預覽Word、Excel、TXT文件之ASP.NET

    這篇文章主要用asp.net技術實現直接在線預覽word、excel、txt文件,有需要的朋友可以參考下
    2015-08-08
  • C#實現可捕獲幾乎所有鍵盤鼠標事件的鉤子類完整實例

    C#實現可捕獲幾乎所有鍵盤鼠標事件的鉤子類完整實例

    這篇文章主要介紹了C#實現可捕獲幾乎所有鍵盤鼠標事件的鉤子類,以完整實例形式分析了C#捕獲鍵盤鼠標事件的鉤子操作技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2016-06-06
  • C#中各種泛型集合的使用方法總結

    C#中各種泛型集合的使用方法總結

    這篇文章介紹了C#各種泛型集合的使用方法,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-10-10

最新評論