コード例 #1
0
        private static PreparedProcess StartProcess([NotNull] ChildProcessStartInfo childProcessStartInfo)
        {
            var processStartInfo = new ProcessStartInfo(childProcessStartInfo.ProcessFileName);

            childProcessStartInfo.Arguments.CopyTo(processStartInfo);

            if (childProcessStartInfo.WorkingDirectory != null)
            {
                processStartInfo.WorkingDirectory = childProcessStartInfo.WorkingDirectory;
            }

            // necessary for redirecting streams
            processStartInfo.UseShellExecute = false;
            // don't pop up a new console window when running the process
            processStartInfo.CreateNoWindow = true;

            processStartInfo.RedirectStandardOutput = true;
            processStartInfo.RedirectStandardError  = true;

            var process = new Process
            {
                StartInfo = processStartInfo,
            };

            return(new PreparedProcess(process, childProcessStartInfo));
        }
コード例 #2
0
        public static ChildProcessResult Exec([NotNull] ChildProcessStartInfo startInfo)
        {
            Verify.ParamNotNull(startInfo, nameof(startInfo));

            var runningProcess = StartProcess(startInfo);

            return(runningProcess.Execute());
        }
コード例 #3
0
            public PreparedProcess([NotNull] Process process, [NotNull] ChildProcessStartInfo startInfo)
            {
                Verify.ParamNotNull(process, nameof(process));
                Verify.ParamNotNull(startInfo, nameof(startInfo));

                this.m_process   = process;
                this.m_startInfo = startInfo;
            }
コード例 #4
0
        private static ChildProcessStartInfo CreateChildProcessStartInfo(
            [NotNull] string processFileName,
            [CanBeNull] ProcessArguments arguments,
            [CanBeNull] string workingDirectory,
            int?successExitCode
            )
        {
            var startInfo = new ChildProcessStartInfo(processFileName)
            {
                WorkingDirectory = workingDirectory,
                SuccessExitCode  = successExitCode,
            };

            if (arguments != null)
            {
                startInfo.Arguments.AddRange(arguments);
            }

            return(startInfo);
        }
コード例 #5
0
        public static async Task <ChildProcessResult> ExecAsync([NotNull] ChildProcessStartInfo startInfo)
        {
            var runningProcess = StartProcess(startInfo);

            return(await runningProcess.ExecuteAsync());
        }