Ejemplo n.º 1
0
        private CommandSpec CreateCommandSpecWrappedWithCmd(
            string command,
            IEnumerable <string> args,
            CommandResolutionStrategy resolutionStrategy)
        {
            var comSpec = Environment.GetEnvironmentVariable("ComSpec") ?? "cmd.exe";

            // Handle the case where ComSpec is already the command
            if (command.Equals(comSpec, StringComparison.OrdinalIgnoreCase))
            {
                command = args.FirstOrDefault();
                args    = args.Skip(1);
            }

            var cmdEscapedArgs = ArgumentEscaper.EscapeAndConcatenateArgArrayForCmdProcessStart(args);

            if (ArgumentEscaper.ShouldSurroundWithQuotes(command))
            {
                command = $"\"{command}\"";
            }

            var escapedArgString = $"/s /c \"{command} {cmdEscapedArgs}\"";

            return(new CommandSpec(comSpec, escapedArgString, resolutionStrategy));
        }
Ejemplo n.º 2
0
        private static CommandSpec CreateComSpecCommandSpec(
            string command,
            IEnumerable <string> args,
            CommandResolutionStrategy resolutionStrategy)
        {
            // To prevent Command Not Found, comspec gets passed in as
            // the command already in some cases
            var comSpec = Environment.GetEnvironmentVariable("ComSpec");

            if (command.Equals(comSpec, StringComparison.OrdinalIgnoreCase))
            {
                command = args.FirstOrDefault();
                args    = args.Skip(1);
            }
            var cmdEscapedArgs = ArgumentEscaper.EscapeAndConcatenateArgArrayForCmdProcessStart(args);

            if (ArgumentEscaper.ShouldSurroundWithQuotes(command))
            {
                command = $"\"{command}\"";
            }

            var escapedArgString = $"/s /c \"{command} {cmdEscapedArgs}\"";

            return(new CommandSpec(comSpec, escapedArgString, resolutionStrategy));
        }