Search code examples
windbg

windbg .shell passes the entire script to cmd, ending in "The command line is too long"


I'm trying to create a folder inside a windbg script file. If I just open windbg, I can do it using .shell -ci "*" mkdir C:\mydir. However, if I put the exact same command in my windbg script, I get error The command line is too long, and looking with Process Monitor I see that windbg passed the entire script to cmd.exe, not just my command.

DebuggerCommands.txt

.echo *** before mkdir ***
.shell -ci "*" mkdir C:\mydir
.echo *** after mkdir ***
$$ many other debugger commands saving stuff to c:\mydir...

Command:

windbg -c '$$>< DebuggerCommands.txt' notepad.exe

Result - windbg opens and shows:

0:000> $$>< DebuggerCommands.txt
*** before mkdir ***
The command line is too long.
.shell: Process exited

0:000>

And looking in Process Monitor, I see C:\Windows\system32\cmd.exe /c "mkdir C:\mydir;.echo *** after mkdir ***;$$ many other debugger commands... etc.


Solution

  • The $$>< command condenses all statements into one single line as specified:

    Token $$><

    Condenses to a single command block: Yes

    This on its own wouldn't matter much. But: some commands are not and can not be terminated by a semicolon.

    One example is the .shell command:

    The entire line after the .shell command will be interpreted as a Windows command (even if it contains a semicolon).

    So: you can't use .shell with $$><, $>< and $$>a<. You might want to try if you can put it into a .block{}. Also: maybe $< or $$< (which don't condense the script) work.

    Otherwise, try finding or implementing an extension with a !-command for this purpose. Perhaps is an option. Just have one PyKD command in your script and let Python do the rest.

    Another example where semicolons don't work ar aliases, since the alias would then simply contain the rest of the file. More obvious: comments. The rest of the file will be ignored.