Wednesday, August 2, 2017

There may be multiple layers of command-line processing

Most shells have some kind of escaping mechanism, so when they run programs, the command line to those programs is processed slightly from what the user typed at the original prompt. At least on Windows, the launched process just gets its command line as one big string and it's up to the application to parse it into individual arguments. When trying to figure out why a program isn't comprehending its arguments as intended, it's important to understand all the layers of processing.

On Windows, you can use PowerShell to test one layer. This command prints the command line given to powershell.exe without any extra processing; it reflects how the calling process adjusted the user input:

powershell -c [environment]::commandline # text to test here

Since the octothorpe comments out everything after it, PowerShell just runs the command that prints to the command line, which includes the text after the comment.

No comments:

Post a Comment