最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

復(fù)制代碼 代碼如下:

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

復(fù)制代碼 代碼如下:

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;
        }
    }
}

相關(guān)文章

最新評論

明星| 安图县| 深泽县| 阿拉善左旗| 金塔县| 建湖县| 红原县| 涞水县| 涿鹿县| 光泽县| 甘南县| 乌鲁木齐县| 揭阳市| 桃江县| 二连浩特市| 瑞昌市| 平湖市| 保德县| 阿坝县| 潍坊市| 青岛市| 固阳县| 甘泉县| 杭州市| 上虞市| 葵青区| 常德市| 青岛市| 平塘县| 嘉善县| 浦北县| 伊春市| 镇平县| 新河县| 阜南县| 鄯善县| 焦作市| 特克斯县| 广汉市| 灵武市| 诸城市|