void RunTool(ExternalTool tool)
        {
            // Set these to somewhat useful values in case StingParser.Parse() passes when being called on one of them.
            string command = tool.Command;
            string args    = tool.Arguments;

            // This needs it's own try/catch because if parsing these messages fail, the catch block after
            // the second try would also throw because MessageService.ShowError() calls StringParser.Parse()
            try {
                command = StringParser.Parse(tool.Command);
                args    = StringParser.Parse(tool.Arguments);
            } catch (Exception ex) {
                MessageService.ShowError("${res:XML.MainMenu.ToolMenu.ExternalTools.ExecutionFailed} '" + ex.Message);
                return;
            }

            if (tool.PromptForArguments)
            {
                args = MessageService.ShowInputBox(tool.MenuCommand, "${res:XML.MainMenu.ToolMenu.ExternalTools.EnterArguments}", args);
                if (args == null)
                {
                    return;
                }
            }

            if (string.IsNullOrEmpty(args) || args.Trim('"', ' ').Length == 0)
            {
                args = "";
            }

            try {
                ProcessRunner processRunner = new ProcessRunner();
                processRunner.WorkingDirectory = DirectoryName.Create(StringParser.Parse(tool.InitialDirectory));
                if (tool.UseOutputPad)
                {
                    processRunner.RunInOutputPadAsync(TaskService.BuildMessageViewCategory, command, ProcessRunner.CommandLineToArgumentArray(args)).FireAndForget();
                }
                else
                {
                    processRunner.CreationFlags = ProcessCreationFlags.CreateNewConsole;
                    processRunner.Start(command, ProcessRunner.CommandLineToArgumentArray(args));
                }
            } catch (Exception ex) {
                MessageService.ShowError("${res:XML.MainMenu.ToolMenu.ExternalTools.ExecutionFailed} '" + command + " " + args + "'\n" + ex.Message);
            }
        }
 public void StartCommandLine(string commandLine)
 {
     string[] args = ProcessRunner.CommandLineToArgumentArray(commandLine);
     Start(args.FirstOrDefault() ?? "", args.Skip(1).ToArray());
 }
Example #3
0
        public async void Run()
        {
            SvcUtilMessageView.ClearText();

            var commandLine = new SvcUtilCommandLine(Options);

            commandLine.Command = GetSvcUtilPath();
            using (ProcessRunner processRunner = new ProcessRunner()) {
                this.ExitCode = await processRunner.RunInOutputPadAsync(SvcUtilMessageView.Category, commandLine.Command, ProcessRunner.CommandLineToArgumentArray(commandLine.Arguments));
            }
            if (ProcessExited != null)
            {
                ProcessExited(this, new EventArgs());
            }
        }