8/30/2008

08-30-08 - 3

I'm seeing some really weird shit with DOS and backslash. Apparently in "cmd" the backslash works as an escape character. Not for normal characters, like \X for any alpha X is not an escape, but \" and \\ are special. \" is a quote char, and \\ is a single backslash. Also, the DOS 'echo' command is special in that it doesn't do any fancy processing. I'm not sure if this escaping is being done by the cmd environment, or if it's being done by the MSVC runtime before it gets to argc/argv.

In particular, I made a little program called "echoargs" that just outputs argc & argv. It makes the following output :

c:\>echoargs "hello world\"
argc : 2
0:echoargs
1:hello world"

A more full line :

c:\src\chuksh>echoargs "hello world\" stuff\\" crap
argc : 3
0:echoargs
1:hello world" stuff\
2:crap

WTF this is seriously screwy. Supposedly the escape char in DOS is the caret ^ , but it's doing some escaping with backslash !? WTF

I can sort of hack a fix for my shell apps by looking for a single quote char in the middle of args and guessing where that came from, but seriously !?

No comments:

old rants