Ejemplo n.º 1
0
        public static string Run(string fileName, string arguments, string directory)
        {
            //实例化一个进程类
            Process procExe = new Process();

            //获得系统信息,使用的是 systeminfo.exe 这个控制台程序
            //procExe.StartInfo.FileName = CurrentContext.Server.MapPath("/") + strSvnExePath;
            if (!string.IsNullOrEmpty(directory))
            {
                procExe.StartInfo.WorkingDirectory = directory;
            }
            procExe.StartInfo.FileName = fileName;

            if (!string.IsNullOrEmpty(arguments))
            {
                procExe.StartInfo.Arguments = arguments;
            }

            //将procExe的标准输入和输出全部重定向到.NET的程序里

            procExe.StartInfo.UseShellExecute        = false; //此处必须为false否则引发异常
            procExe.StartInfo.RedirectStandardInput  = true;  //标准输入
            procExe.StartInfo.RedirectStandardOutput = true;  //标准输出
            procExe.StartInfo.RedirectStandardError  = true;

            //不显示命令行窗口界面
            procExe.StartInfo.CreateNoWindow = true;
            procExe.StartInfo.WindowStyle    = ProcessWindowStyle.Hidden;
            var loger = new ZyGames.GameService.BaseService.LogService.BaseLog();

            try
            {
                procExe.Start(); //启动进程
            }
            catch (Exception Ex)
            {
                loger.SaveLog(Ex);
                return(Ex.Message);
            }

            //获取输出
            //需要说明的:此处是指明开始获取,要获取的内容,
            //只有等进程退出后才能真正拿到
            string strOutput = procExe.StandardOutput.ReadToEnd() + procExe.StandardError.ReadToEnd();

            loger.SaveLog(strOutput);

            procExe.WaitForExit(); //等待控制台程序执行完成
            procExe.Close();       //关闭该进程
            procExe.Dispose();
            return(strOutput);
        }
Ejemplo n.º 2
0
        public static string Run(string fileName, string arguments, string directory)
        {
            //实例化一个进程类
            Process procExe = new Process();

            //获得系统信息,使用的是 systeminfo.exe 这个控制台程序
            //procExe.StartInfo.FileName = CurrentContext.Server.MapPath("/") + strSvnExePath;
            if (!string.IsNullOrEmpty(directory))
            {
                procExe.StartInfo.WorkingDirectory = directory;
            }
            procExe.StartInfo.FileName = fileName;

            if (!string.IsNullOrEmpty(arguments))
            {
                procExe.StartInfo.Arguments = arguments;
            }

            //将procExe的标准输入和输出全部重定向到.NET的程序里

            procExe.StartInfo.UseShellExecute = false; //此处必须为false否则引发异常
            procExe.StartInfo.RedirectStandardInput = true; //标准输入
            procExe.StartInfo.RedirectStandardOutput = true; //标准输出
            procExe.StartInfo.RedirectStandardError = true;

            //不显示命令行窗口界面
            procExe.StartInfo.CreateNoWindow = true;
            procExe.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            var loger = new ZyGames.GameService.BaseService.LogService.BaseLog();
            try
            {
                procExe.Start(); //启动进程
            }
            catch (Exception Ex)
            {
                loger.SaveLog(Ex);
                return Ex.Message;
            }

            //获取输出
            //需要说明的:此处是指明开始获取,要获取的内容,
            //只有等进程退出后才能真正拿到
            string strOutput = procExe.StandardOutput.ReadToEnd() + procExe.StandardError.ReadToEnd();
            loger.SaveLog(strOutput);

            procExe.WaitForExit();//等待控制台程序执行完成
            procExe.Close();//关闭该进程
            procExe.Dispose();
            return strOutput;
        }
Ejemplo n.º 3
0
        public static string Run(string fileName, string arguments, string directory)
        {
            //ʵ����һ��������
            Process procExe = new Process();

            //���ϵͳ��Ϣ��ʹ�õ��� systeminfo.exe �������̨����
            //procExe.StartInfo.FileName = CurrentContext.Server.MapPath("/") + strSvnExePath;
            if (!string.IsNullOrEmpty(directory))
            {
                procExe.StartInfo.WorkingDirectory = directory;
            }
            procExe.StartInfo.FileName = fileName;

            if (!string.IsNullOrEmpty(arguments))
            {
                procExe.StartInfo.Arguments = arguments;
            }

            //��procExe�ı�׼��������ȫ���ض���.NET�ij�����

            procExe.StartInfo.UseShellExecute = false; //�˴�����Ϊfalse���������쳣
            procExe.StartInfo.RedirectStandardInput = true; //��׼����
            procExe.StartInfo.RedirectStandardOutput = true; //��׼���
            procExe.StartInfo.RedirectStandardError = true;

            //����ʾ�����д��ڽ���
            procExe.StartInfo.CreateNoWindow = true;
            procExe.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            var loger = new ZyGames.GameService.BaseService.LogService.BaseLog();
            try
            {
                procExe.Start(); //�������
            }
            catch (Exception Ex)
            {
                loger.SaveLog(Ex);
                return Ex.Message;
            }

            //��ȡ���
            //��Ҫ˵���ģ��˴���ָ����ʼ��ȡ��Ҫ��ȡ�����ݣ�
            //ֻ�еȽ����˳�����������õ�
            string strOutput = procExe.StandardOutput.ReadToEnd() + procExe.StandardError.ReadToEnd();
            loger.SaveLog(strOutput);

            procExe.WaitForExit();//�ȴ�����̨����ִ�����
            procExe.Close();//�رոý���
            procExe.Dispose();
            return strOutput;
        }