Skip to content

Instantly share code, notes, and snippets.

@yeputons
Last active January 3, 2016 18:39
Show Gist options
  • Save yeputons/8503895 to your computer and use it in GitHub Desktop.
Save yeputons/8503895 to your computer and use it in GitHub Desktop.
Demonstration of cmd.exe escaping rules
@cmd.exe /s /c "x.cmd ^ ^"
@cmd.exe /s /c "x.cmd ^^ ^^"
@cmd.exe /s /c "x.cmd ^^^ ^^^"
@cmd.exe /s /c "x.cmd ^^^^ ^^^^"
@cmd.exe /s /c "x.cmd ^^^^^ ^^^^^"
@cmd.exe /s /c "x.cmd ^^^^^^ ^^^^^^"
@cmd.exe /s /c "x.cmd ^^^^^^^ ^^^^^^^"
@cmd.exe /s /c "x.cmd ^^^^^^^^ ^^^^^^^^"
@echo.
@cmd.exe /s /c "x.cmd "^" "^""
@cmd.exe /s /c "x.cmd "^^" "^^""
@cmd.exe /s /c "x.cmd "^^^" "^^^""
@cmd.exe /s /c "x.cmd "^^^^" "^^^^""
@cmd.exe /s /c "x.cmd "^^^^^" "^^^^^""
@cmd.exe /s /c "x.cmd "^^^^^^" "^^^^^^""
@cmd.exe /s /c "x.cmd "^^^^^^^" "^^^^^^^""
@cmd.exe /s /c "x.cmd "^^^^^^^^" "^^^^^^^^""
@call y.bat "%*"
@z.exe %*
#include <cstdio>
#include <windows.h>
int main(int argc, char* argv[]) {
printf("%30s; %d;", GetCommandLine(), argc);
for (int i = 1; i < argc; i++)
printf(" %20s;", argv[i]);
printf("\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment