コード例 #1
0
        public static CommandLineInvocation New(string command, string arguments, bool suppressConsoleOutput = false)
        {
            DataReceivedEventHandler receiveOutputData;
            DataReceivedEventHandler receiveErrorData;

            if (suppressConsoleOutput)
            {
                receiveOutputData = CommandLineInvocation.DoNothing;
                receiveErrorData  = CommandLineInvocation.DoNothing;
            }
            else
            {
                receiveOutputData = CommandLineInvocation.ConsoleReceiveOutputData;
                receiveErrorData  = CommandLineInvocation.ConsoleReceiveErrorData;
            }

            var invocation = new CommandLineInvocation()
            {
                Command           = command,
                Arguments         = arguments,
                ReceiveOutputData = receiveOutputData,
                ReceiveErrorData  = receiveErrorData,
            };

            return(invocation);
        }
コード例 #2
0
        public static CommandLineInvocationResult Run(string command, string arguments)
        {
            var invocation = new CommandLineInvocation()
            {
                Command   = command,
                Arguments = arguments,
            };

            var result = CommandLineInvocationRunner.Run(invocation);

            return(result);
        }
コード例 #3
0
        public static CommandLineInvocationResult Run(CommandLineInvocation invocation)
        {
            var result = new CommandLineInvocationResult();

            void ReceiveOutputData(object sender, DataReceivedEventArgs e)
            {
                invocation.ReceiveOutputData(sender, e);

                result.ReceiveOutputData(sender, e);
            }

            void ReceiveErrorData(object sender, DataReceivedEventArgs e)
            {
                invocation.ReceiveErrorData(sender, e);

                result.ReceiveErrorData(sender, e);
            }

            result.ExitCode = CommandLineInvocationRunner.Run(invocation.Command, invocation.Arguments, ReceiveOutputData, ReceiveErrorData);

            return(result);
        }