[an error occurred while processing this directive] Node:Special chars, Next:, Previous:Disable globbing, Up:Command line

16.3 How to pass command-line arguments with quotes or @

Q: I have a file with a single quote in its name, but the quote seems to be stripped away when I pass it to my program ....

Q: How do I pass a command-line argument which contains double quotes?

Q: How do I pass an argument which begins with the @ character?

A: These special characters on the command-line arguments are handled by the filename expansion ("globbing") code before they are passed to the main function (see description of filename expansion), and the quote characters serve to protect the arguments from expansion. You should escape-protect the quote characters with a backslash in order for them to be treated as literal characters. For example, if you have a file called myfile.c'v, type it as myfile.c\'v when you call your program. If you have single quotes in your program arguments and you don't want those arguments to be expanded, then surround them by double quotes, like this: "*.c'v". The program will get the string *.c'v with the double quotes stripped away.

Note that backslashes are only special if they are in front of a quote or a backslash (they also serve as DOS directory separators, remember?). This is also different from what you get under a Unix shell, where a backslash quotes any character.

The @ character serves to signal a response file (see the description of response file method), so it's also special. To pass an argument whose first character is @, surround that argument with single or double quotes, otherwise it will be taken as a name of a response file which holds the actual command line.

You can quote only some parts of the wildcard to protect only those parts from expansion; the unquoted parts will still be expanded. This allows to use wildcards with embedded whitespace and expand file names with special characters which need to be quoted, like in c:/Prog*' 'F* (which should expand into c:/Program Files) and *.c"'"v (which should expand into all files with the *.c'v extension).


[an error occurred while processing this directive]