A place for me to keep track of hard to find information related to the use of Microsoft Visual Studio, System Center and SharePoint products.

Tuesday, April 20, 2010

What is up with that %@#*&( batch file?!?!

So I'm working on a batch file to run some post-build events in Visual Studio, but when i run the build I notice something funny in the output window:

{{[[@ECHO OFF is not recognized as a valid command

Disclaimer: That might not be exactly how the error read, because I've already fixed the error and I'm too lazy to recreate it to get the exact wording, but you get the idea.

Now, the first line in my batch file is in fact a valid command, but there are all of these funny characters at the beginning of the line in the output window. So I go back to the actual batch file and those funny characters are not there.
So here I am scratching my head, thinking "I didn't put those characters there, so who did?" Of course, my first reaction is to blame the machine!
After fiddling around with it, I discovered that whenever you create a new text file in Visual Studio and make it a batch file, it introduces these funny characters to the beginning of the file. I can only speculate (since I didn't actually look at the bytes in the file), but I think it might be a Unicode vs ASCII encoding issue.

Long story short: if you want to create a batch file, first create it Notepad. Save it off and then edit it in Visual Studio and you won't have any problems with encoding.

No comments:

Post a Comment

Followers