c# 执行应用程序实例

        public static void DoRAR(string rarFile, string toRarDirecotry, string RARProgramFilePath)
        {
            string arguments = @"a -m0 -ep1 ""{0}"" ""{1}""";
            arguments = string.Format(
                arguments,
                rarFile,
                toRarDirecotry
            );

            var proc = Process.Start(new ProcessStartInfo
            {
                FileName = RARProgramFilePath,
                Arguments = arguments,
                UseShellExecute = false,
                RedirectStandardOutput = true,
                RedirectStandardError = true,
                RedirectStandardInput = true
            }
            );
            proc.WaitForExit();

            if (proc.ExitCode != 0)
            {
                throw new Exception("Run WinRAR RAR Command Failed!, Exit Code: " + proc.ExitCode +
                    ", Details StandardOuput: " + proc.StandardOutput.ReadToEnd() +
                    ",StandardError" + proc.StandardError.ReadToEnd() +
                    ",StandardInput" + proc.StandardInput +
                    ",Site" + proc.Site);
            }
        }

posted @ 2012-10-16 18:03  doo  阅读(464)  评论(0编辑  收藏  举报