private CommandSpec CreateCommandSpecWrappedWithCmd( string command, IEnumerable <string> args) { 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.IsSurroundedWithQuotes(command) && // Don't quote already quoted strings ArgumentEscaper.ShouldSurroundWithQuotes(command)) { command = $"\"{command}\""; } var escapedArgString = $"/s /c \"{command} {cmdEscapedArgs}\""; return(new CommandSpec(comSpec, escapedArgString)); }