Skip to content

escapeWin32CmdCommandArg

escapeWin32CmdCommandArg(expr): string

Defined in: command/escape-win32-cmd-command-arg.ts:19

Escape a string to be safely used as a shell argument in Windows cmd.exe

It adds double quotes around a string and escapes any existing problematic characters (such as %, !, and “) by replacing them with spaces. Backslashes are escaped by doubling them.

Example:

const unsafe = 'A "complex" %string% with !special! chars \\';
const safe = escapeShellArgWindows(unsafe);
console.log(safe); // "A complex string with special chars \\"

string

The string to escape

string

The escaped string