Batch files and accented characters

Solved
baldeagleseyes Posted messages 7 Status Membre -  
baldeagleseyes Posted messages 7 Status Membre -
Hello,

I have a little problem with a batch file. Here is what I have so far:

set /P mytext=Type text: echo %mytext%>>myfile.txt


The problem is that if the user types accented characters, they are replaced by other characters in the .txt file. This can make the text unreadable.

What should I do?

Thank you.

3 réponses

baldeagleseyes Posted messages 7 Status Membre 3
 
Here, I think I've found ...

set /P mytext=Type text:
chcp 1252
echo %mytext% >> myfile.txt
chcp 850

I had already tried with the CHCP command which changes the active character code page but without success.

By default, the code page in the console (cmd.exe) is 850 and 1252 in Windows. So at the beginning of the script, it's 850, which allows for proper input in the SET command. I then change the code page to 1252. The content of the variable is not affected. I execute the ECHO command with the redirection ">>". The content of the variable is thus written to the text file with code page 1252. I then reactivate code page 850 to continue executing the batch. When I later open the text file in Notepad, I see exactly what the user has written.
2
baldeagleseyes Posted messages 7 Status Membre 3
 
Thank you Quester4.

The problem is that I have no control over what my users will write and it's certain that they will include accents or other special characters.

Is there something I can put in my batch to eliminate these characters before the "echo %montexte%>>monfichier.txt"?
1
Quester4 Posted messages 150 Status Membre 126
 
Hi,
The Batch doesn't handle accents. This is due to the difference between the syntaxes used; you write accents in ASCII, whereas Batch operates with the ANSI system.
The only thing you can do is not write accents.
Or you can write manually in the file...
0