Computing.Net > Forums > Programming > Batch: accented characters problem

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

Batch: accented characters problem

Reply to Message Icon

Original Message
Name: Elinor
Date: July 30, 2008 at 11:35:24 Pacific
Subject: Batch: accented characters problem
OS: Win2K
CPU/Ram: ---
Manufacturer/Model: ---
Comment:

Hi,

I am trying to write a batch script which will retrieve available batch command names as stated by "help" and output the command help to a text/HTML format.

I have run into one major problem.

Accented characters (french) are not output properly to the output file even though they "echo" properly on the console.

Example: outputs "paramŠtres" instead of "paramètres".

Does anyone know how to solve this issue?

Elinor Hurst
http://elinorhurst.blogspot.com


Report Offensive Message For Removal


Response Number 1
Name: Elinor
Date: July 30, 2008 at 13:02:45 Pacific
Reply:

Well, I am sorry I troubled you with this in the first place. I have found a solution.

Because I am outputting to HTML I replaced the accented characters with the corresponding HTML entities.

To do this properly, I had to open the file using EDIT to enter the accented characters (they look strange in Notepad but the script works on runtime).

Here is the replacement code I use (in FOR loop with delayed expansion enabled):
set str=!str:…=^à!
set str=!str:‚=^é!
set str=!str:Š=^è!
set str=!str:ˆ=^ê!
set str=!str:‰=^ë!
set str=!str:Œ=^î!
set str=!str:‹=^ï!
set str=!str:“=^ô!
set str=!str:—=^ù!
set str=!str:–=^û!
set str=!str:‡=^ç!

Where using EDIT, "…" shows up as "à", "‚" as "é", "Š" as "è", etc.

Hopefully this won't all be lost and someone somewhere will also find this info useful =D

Elinor

Elinor Hurst
http://elinorhurst.blogspot.com


Report Offensive Follow Up For Removal

Response Number 2
Name: Mechanix2Go
Date: July 30, 2008 at 15:59:19 Pacific
Reply:

I put your example line in a file and it seems to echo OK. What am I missing?

Example: outputs "paramStres" instead of "paramètres".


=====================================
If at first you don't succeed, you're about average.

M2


Report Offensive Follow Up For Removal

Response Number 3
Name: Razor2.3
Date: July 30, 2008 at 17:44:43 Pacific
Reply:

Mechanix2Go: What am I missing?
The discrepancy in his code pages, presumably.


Report Offensive Follow Up For Removal

Response Number 4
Name: Elinor
Date: July 31, 2008 at 01:01:01 Pacific
Reply:

Hi,

Thanks for your responses.

Razor2.3: Eh?

Mechanix2Go:
If you echo "paramŠtres" to screen it will show fine. If you redirect it to a txt/HTML file it will not show as it should i.e. "paramètres", so I was getting lots of weird-looking output.

(for instance: echo paramŠtres > test.txt)

This is my current code which works but obviously any suggestions on how to make it better (and perhaps avoid the ugly character replacements) are more than welcome!

What it does simply is retrieve all command names (using help) then outputs the detailed information for each command to an HTML page ("help commandname" output).

Note: replace #a with <a (there are two).


<code>
@echo off

:init
setlocal enabledelayedexpansion
set out_dir=site
set page_sub=pages
set page_dir=%out_dir%\%page_sub%
if not exist %page_dir% mkdir %page_dir%
goto create_site

:create_site
set ifile=%out_dir%\index.html
> %ifile% echo ^<html^>^<head^>^<title^>Commands index^</title^>^</head^>
>> %ifile% echo ^<body^>
for /F "tokens=1" %%C in ('help') do (
call :set_is_command %%C
echo "is_command (%%C): !is_command!"
if "!is_command!"=="1" (
set cfile=%page_dir%\%%C.html
>> %ifile% echo ^#a href="%page_sub%\%%C.html"^>%%C^</a^>^<br/^>
:: set cfile=CON
> !cfile! echo ^<html^>^<head^>^<title^>%%C^</title^>^</head^>
>> !cfile! echo ^<body^>^<h2^>%%C^</h2^>^
for /F "delims=" %%T in ('help %%C') do (
set str=%%T
set str=!str:…=^&agrave;!
set str=!str:‚=^&eacute;!
set str=!str:Š=^&egrave;!
set str=!str:ˆ=^&ecirc;!
set str=!str:‰=^&euml;!
set str=!str:Œ=^&icirc;!
set str=!str:‹=^&iuml;!
set str=!str:“=^&ocirc;!
set str=!str:—=^&ugrave;!
set str=!str:–=^&ucirc;!
set str=!str:‡=^&ccedil;!
set str=!str:ÿ=^&nbsp;!
>> !cfile! echo !str!
)
>> !cfile! echo ^<br/^>^<br/^>
>> !cfile! echo ^#a href="../index.html"^>Back to index/Retour ^&agrave; l'index^</a^>
>> !cfile! echo ^</pre^>^</body^>^</html^>
)
)
>> %ifile% echo ^</body^>
>> %ifile% echo ^</html^>

goto end

:set_is_command
set name=%~1
set is_command=1
if not "%name%"=="" (
set num=1
for /F "usebackq tokens=1 delims=ABCDEFGHIJKLMNOPQRSTUVWXYZ" %%W IN ('%name%') do (
set num=0
)
set is_command=!num!
)
goto blackhole

:end
echo Press any key to quit...
pause > NUL

:blackhole
</code>

I haven't been able to find any other "workaround" to make those characters appear as they should in the HTML output without replacing them with the corresponding entities (or "notepad version" of those characters, if that makes any sense).

Thanks again for your help.

Elinor Hurst
http://elinorhurst.blogspot.com


Report Offensive Follow Up For Removal

Response Number 5
Name: Razor2.3
Date: July 31, 2008 at 01:22:32 Pacific
Reply:

Elinor: Razor2.3: Eh?
Oh, don't mind me. I just said what you said, only in 7 words.


Report Offensive Follow Up For Removal


Response Number 6
Name: Elinor
Date: July 31, 2008 at 01:43:46 Pacific
Reply:

Razor 2.3:Oh, don't mind me. I just said what you said, only in 7 words.

If you have a more elegant solution, which no doubt you do, why don't you just share it or express constructively what it is you don't like about my code and why? Thank you.

Elinor

Elinor Hurst
http://elinorhurst.blogspot.com


Report Offensive Follow Up For Removal

Response Number 7
Name: Razor2.3
Date: July 31, 2008 at 04:49:22 Pacific
Reply:

Elinor: If you have a more elegant solution, which no doubt you do, why don't you just share it or express constructively what it is you don't like about my code and why?
I never said I had an alternate solution, nor did I say yours was inferior.


Report Offensive Follow Up For Removal

Response Number 8
Name: Elinor
Date: July 31, 2008 at 05:07:27 Pacific
Reply:

Razor2.3:I never said I had an alternate solution, nor did I say yours was inferior.

Oh. Right. In that case, I think I may have got the wrong end of the stick altogether re your posts, so ... well, apologies for that and thanks for reading this far :).

Elinor

Elinor Hurst
http://elinorhurst.blogspot.com


Report Offensive Follow Up For Removal






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home



Results for: Batch: accented characters problem

Batch pipe character problem
    Summary: I am making my first command prompt game. The box that is the level, looks like this: _________ | | | | | | | | | | |_________| But echo thinks...
www.computing.net/answers/programming/batch-pipe-character-problem/15960.html

Batch/VC++ choice problem
    Summary: hey stuby, trust me when i say get rid of the equal sign, your teacher will say the same thing, if he doesn't drop out, and go to a different school, lol.. before you can make this a exe, you need to ...
www.computing.net/answers/programming/batchvc-choice-problem/9057.html

DOS - batch variables
    Summary: <blockquote> Response Number 1 Name: Mechanix2Go Date: February 07, 2007 at 13:27:02 Pacific Homepage: Golden-Triangle Subject: DOS - batch variables Reply: To test for equality: if %SDC%==0 Th...
www.computing.net/answers/programming/dos-batch-variables/15058.html








Which MP3 player do you have?

iPod/iPhone
Zune
Something Else
None


View Results

Poll Finishes In 2 Days.
Discuss in The Lounge
Poll History






Data Recovery Software