PDA

View Full Version : .txt and .bat file encoding clashes. Problem.



dotbond
27-07-2010, 09:08 PM
Hi. I have an installation log file saved as a .txt file from installing MS Dynamics CRM for Outlook. I am trying to parse it with a .bat file, looking for a particular string.
The problem seems to be that the generated .txt file is encoded in UCS-2 Little Endian and the .bat file is encoded in ANSI. The bat file cannot read the txt file.
I have tried saving the bat file in the same encoding spec as the txt file but then the bat file does not work.
I need to parse the txt file in real time looking for the string to say that the install was successful, basically

Anyone come across this problem, or a similar problem?

Thanks
Trev

mikebartnz
27-07-2010, 09:31 PM
Don't reinvent the wheel just download WinGrep. (http://www.wingrep.com/)

dotbond
27-07-2010, 10:30 PM
Thanks for the reply. I have had a look at the program suggested but I need a batch file, or something similar, as the batch file is to be deployed to networked computers to determine which version of Windows they are running and then start a silent install of Dynamics CRM using switches and then updates then configuring the program via an XML config file. So it's doing more than just finding a string.

Trev

MushHead
27-07-2010, 10:50 PM
Have you looked at Microsoft's PowerShell, or maybe just Python or Perl? I would have thought that any of these modern languages could handle UCS-2.

Does the .txt file have special prefix bytes at the start of the file? I'm sure there's some standard codes stored as the first couple of bytes which specify the encoding used in the file. Does Notepad open the .txt file correctly? I think it should if the encoding bytes are present.

mikebartnz
27-07-2010, 11:11 PM
Thanks for the reply. I have had a look at the program suggested but I need a batch file, or something similar, as the batch file is to be deployed to networked computers to determine which version of Windows they are running and then start a silent install of Dynamics CRM using switches and then updates then configuring the program via an XML config file. So it's doing more than just finding a string.

Trev
I didn't have a thorough look at the site but it has a command line version as well with a replace function. I haven't used it for years as I no longer use Windows.

dotbond
28-07-2010, 09:31 AM
No I haven't looked at Powershell or Perl. May have to if time allows.

I have been opening up the files using Notepad++ and that was telling me the encoding format. There aren't any prefix bytes at the start of the file that I can see.
Yes Notepad and Notepad++ both open the files correctly and I can read them.