japanase cmd

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
einstein1969
Expert
Posts: 960
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: japanase cmd

#16 Post by einstein1969 » 09 Apr 2014 06:03

thanks Carlos!

In my code have found this:

detect charcode of files:

Code: Select all

@if(0)==(0) ECHO OFF
REN "%~f1" "%~nx1.txt"
CScript.exe //NoLogo //E:JScript "%~f0" "%~f1.txt"
REN "%~f1.txt" "%~nx1"
GOTO :EOF
@end
var htmlfile=WScript.GetObject(WScript.Arguments.Item(0),'htmlfile');
while(htmlfile.readyState!='complete') WScript.Sleep(100);
WScript.Echo(htmlfile.charset);


type bigendian:

Code: Select all

@if(0)==(0) ECHO OFF
CScript.exe //NoLogo //E:JScript "%~f0" "%~f1"
GOTO :EOF
@end
var htmlfile=WScript.GetObject(WScript.Arguments.Item(0),'htmlfile');
while(htmlfile.readyState!='complete') WScript.Sleep(100);
WScript.Echo(htmlfile.body.innerText);
// unicode: change last line with
// new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1,true).Write(htmlfile.body.innerText);


equivalent for file ? the TYPE work only for little endian?  are BOM

Code: Select all

from unicode
start /min /wait cmd /c chcp.com 65001 ^& cmd /c type %1 ^>%2

to unicode
start /min /wait cmd /c chcp.com 65001 ^& ^( set /p x=""^<nul ^& cmd /u /c type %1 ^) ^>%2


einstein1969

Liviu
Expert
Posts: 470
Joined: 13 Jan 2012 21:24

Re: japanase cmd

#17 Post by Liviu » 09 Apr 2014 10:38

carlos wrote:I found a solution for use the utf 8 codepage using a batch script on windows xp.

This is the trick

Code: Select all

(
chcp 65001 >nul
echo do something
rem restore the codepage
chcp 850 >nul
)

This has been known to work, and has been used before to, for example, convert a file to UTF-8. You can find examples of that both here on dostips and elsewhere.

But it does not and cannot work to _read_ a UTF-8 encoded file into a variable. In other words, if you replace the "echo do something" line with a for/f file loop, it will _not_ work. Reason why, is the way batch handles codepages during execution:
- the 'in' command of a 'for/f' loop runs in the codepage which is active at the time the nested 'cmd' executes the command - in this case 65001;
- but the 'for/f' evaluates the loop variables according to the original codepage in effect at the time the loop was parsed - in this case whatever codepage was active before the opening parenthesis.

Liviu

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: japanase cmd

#18 Post by aGerman » 09 Apr 2014 11:48

carlos wrote:aGerman, I will download that unicode font.

Unfortunately you would need ConEmu as well because you cannot use unifont in the Windows console.
(some more information ...)

Regards
aGerman

Post Reply