<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; CMD/BAT: О кодировке]]></title>
	<link rel="self" href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=7683&amp;type=atom" />
	<updated>2012-10-09T15:48:01Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.script-coding.com/viewtopic.php?id=7683</id>
		<entry>
			<title type="html"><![CDATA[CMD/BAT: О кодировке]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=64665#p64665" />
			<content type="html"><![CDATA[<p>есть простой код (измененный для хелпа), как сделать по русски на вин 7 ? (изначально было без иконвов и приблуд)<br />оно все по русски, но интересует без изменения шрифта окна (т.е. все в 866)<br /></p><div class="codebox"><pre><code>@echo off
chcp 866 &gt; nul
setlocal ENABLEDELAYEDEXPANSION
set findstr=true
set find=%systemroot%\system32\findstr.exe
set ScriptFullName=%~0
set ScriptName=%~nx0
if not exist &quot;%find%&quot; (
    set findstr=false
    set find=%systemroot%system32\find.exe /i
) else (
    set find=%systemroot%\system32\findstr.exe /i /c:
)

if defined programfiles(x86) set ProgramFiles=%programfiles(x86)%
set PATH=%ProgramFiles%\GPGshell;%PATH%
set gpg.exe=%ProgramFiles%\GNU\GnuPG\pub\gpg.exe
&quot;%gpg.exe%&quot; --no-verbose --batch --no-tty --list-secret-keys --with-colons --fixed-list-mode &gt; &quot;%appdata%\gpgshell\~seckeys.dat&quot;
&quot;%gpg.exe%&quot; --no-verbose --batch --no-tty --list-config --with-colons &gt; &quot;%appdata%\gpgshell\~pubkeys.dat&quot;
echo.&gt;&gt;&quot;%appdata%\~pubkeys.dat&quot;
&quot;%gpg.exe%&quot; --no-verbose --batch --no-tty --list-public-keys --with-fingerprint --with-colons --fixed-list-mode &gt;&gt; &quot;%appdata%\gpgshell\~pubkeys.dat&quot;
set rcpt=
set z=
set /a n=-1
for /f &quot;tokens=1,2,3,4,5* delims=:&quot; %%a in (&#039;find &quot;uid:&quot; ^&lt; &quot;%~dp0~pubkeys.dat&quot;&#039;) do (
    echo ________________________________
    set x=%%~e
    set /a n+=1
    echo !n!. !x!
    set z=!z!!n!
)
set key=0x
set /a quit=0
if exist &quot;%~1&quot; (
echo q. Exit
set /a quit=!n! + 1
choice /c !z!q /m &quot;Выберите ключ&quot;
) else (cd&gt;nul)
set /a n=!ERRORLEVEL! - 1
if %n% equ %quit% (
    echo.
    exit /b 255
)
for /f &quot;tokens=1,2,3,4,5* delims=:&quot; %%a in (&#039;find &quot;pub:&quot; ^&lt; &quot;%~dp0~pubkeys.dat&quot;&#039;) do (
    if !n! equ 0 set key=%key%%%~e
    set /a n-=1
)

if not &quot;%key%&quot;==&quot;0x&quot; (
chcp 1251 &gt; nul
chcp 1251|&quot;%gpg.exe%&quot; -v -o &quot;%~1.gpg&quot; -r %key% -e &quot;%~1&quot; 2&gt; nul
) else (
echo.
echo Press any key to Help...
pause &gt; nul
&quot;%gpg.exe%&quot; --help &gt; %temp%\gpghelp.txt
call :iconv cp1251 cp866 %temp%\gpghelp.txt
type &quot;!iconv!&quot;
echo Press any key...
pause &gt; nul
)
endlocal
chcp 866 &gt; nul
exit /b


:iconv (from,to,input) {
    @@rem Процедура коневертации кодировок, через файл для универсальности
    @@rem
    setlocal
    chcp 866&gt; nul
    set out=%~0
    if &quot;%out:~0,1%&quot;==&quot;:&quot; (
        set out=%out:~1%
        ) else (
        set out=out
        )
    if /i &quot;%~1&quot;==&quot;utf8&quot; (
        set code=65001
        ) else if /i &quot;%~1&quot;==&quot;utf-8&quot; (
        set code=65001
        ) else if /i &quot;%~1&quot;==&quot;cp1251&quot; (
        set code=1251
        ) else if /i &quot;%~1&quot;==&quot;cp866&quot; (
        set code=866
        ) else if /i &quot;%~1&quot;==&quot;iso-8859-5&quot; (
        set code=28595
        ) else if /i &quot;%~1&quot;==&quot;koi8-r&quot; (
        set code=20866
        ) else if not &quot;%~1&quot;==&quot;&quot; (
        set code=%~1
        ) else (
        set code=1251
        )
    if /i &quot;%~2&quot;==&quot;utf8&quot; (
        set tocode=65001
        ) else if /i &quot;%~2&quot;==&quot;utf-8&quot; (
        set tocode=65001
        ) else if /i &quot;%~2&quot;==&quot;cp1251&quot; (
        set tocode=1251
        ) else if /i &quot;%~2&quot;==&quot;cp866&quot; (
        set tocode=866
        ) else if /i &quot;%~2&quot;==&quot;iso-8859-5&quot; (
        set tocode=28595
        ) else if /i &quot;%~2&quot;==&quot;koi8-r&quot; (
        set tocode=20866
        ) else if not &quot;%~2&quot;==&quot;&quot; (
        set tocode=%~2
        ) else (
        set tocode=1251
        )
    set outtype=file
    set utf16=%temp%\%RANDOM%.utf-16
    set ftemp=%temp%\%RANDOM%.%code%
    if exist &quot;%~3&quot; (
        set stream=type &quot;%~3&quot;
        ) else (
        set outtype=var
        set string=&quot;%~3&quot;
        set string=!string:^|=^^^|!
        echo !string:~1,-1!&gt; &quot;%ftemp%&quot;
        set stream=type &quot;%ftemp%&quot;
        )
    call :getfileinfo path &quot;%ScriptFullName%&quot;
    if exist &quot;%getfileinfo%\iconv\iconv.exe&quot; (
        %stream%| &quot;%getfileinfo%\iconv\iconv.exe&quot; -f %~1 -t %~2 &gt; &quot;%ftemp%.%tocode%&quot;
        goto end_iconv
        )
    call :getchar &quot;%ScriptFullName%&quot; &quot;=FF&quot;
    set &quot;mark=%getchar%&quot;
    call :getchar &quot;%ScriptFullName%&quot; &quot;=FE&quot;
    set &quot;mark=%mark%%getchar%&quot;
    chcp 866 &gt; nul
    echo.%mark%&gt;&gt; %utf16%
    chcp %tocode% &gt; nul
    chcp %code% |&gt;&gt; &quot;%utf16%&quot; cmd /u /c &quot;%stream% &amp; chcp %tocode% &gt; nul&quot;
    chcp %tocode% &gt; nul
    type &quot;%utf16%&quot; &gt; &quot;%ftemp%.%tocode%&quot;
    :end_iconv
    chcp 866 &gt; nul
    set ret=%ftemp%.%tocode%
    if /i &quot;%outtype%&quot;==&quot;var&quot; (
        for /f &quot;delims=&quot; %%i in (&#039;type &quot;%ftemp%.%tocode%&quot;&#039;) do (
            set ret=%%i
            )
        del /q &quot;%ftemp%.%tocode%&quot;
        )
    if exist &quot;%ftemp%&quot; del /q &quot;%ftemp%&quot;
rem    if exist &quot;%utf16%&quot; del /q &quot;%utf16%&quot;
    endlocal &amp; set %out%=%ret%
    exit /b 0
    }

:getfileinfo (info,filepath) {
    @@rem Процедура получения свойств файла
    @@rem
    setlocal
    set out=%~0
    if &quot;%out:~0,1%&quot;==&quot;:&quot; (
        set out=%out:~1%
        ) else (
        set out=out
        )
    set info=undefined
    set opt=%~1
    if /i &quot;%opt%&quot;==&quot;name&quot; (
        set info=%~n2
        ) else if /i &quot;%opt%&quot;==&quot;ext&quot; (
        set info=%~x2
        ) else if /i &quot;%opt%&quot;==&quot;fname&quot; (
        set info=%~nx2
        ) else if /i &quot;%opt%&quot;==&quot;fpath&quot; (
        set info=%~f2
        ) else if /i &quot;%opt%&quot;==&quot;spath&quot; (
        set info=%~s2
        ) else if /i &quot;%opt%&quot;==&quot;size&quot; (
        set /a info=0
        set /a info=%~z2 2&gt; nul
        ) else if /i &quot;%opt%&quot;==&quot;drive&quot; (
        set info=%~d2
        ) else if /i &quot;%opt%&quot;==&quot;folder&quot; (
        set info=%~p2
        ) else if /i &quot;%opt%&quot;==&quot;path&quot; (
        set info=%~dp2
        )
    set /a ret=1
    if exist &quot;%~2&quot; set /a ret=0
    endlocal &amp; set %out%=%info%
    exit /b %ret%
    }

:getchar (table,asc) {
    @@rem Процедура получения нужного символа по коду
    @@rem
    setlocal
    set out=%~0
    if &quot;%out:~0,1%&quot;==&quot;:&quot; (
        set out=%out:~1%
        ) else (
        set out=out
        )
    set char=
    set table=%~1
    set asc=%~2
    for /f &quot;tokens=2&quot; %%u in (&#039;%find%&quot;####&quot; &quot;%table%&quot; ^| %find%&quot;%asc%&quot;&#039;) do (
        set &quot;char=%%~u&quot;
        )
    endlocal &amp; set &quot;%out%=%char%&quot;
    exit /b 0
    }

goto :eof

#Table characters
#### \0 =00
####   =01
####   =02
####   =03
####   =04
####   =05
####   =06
####   =07
####   =08
#### \t =09
#### \n =0A
####   =0B
####   =0C
#### \r =0D
####   =0E
#### д  =0F
####   =10
####   =11
####   =12
####   =13
#### &amp;#9570;  =14
#### з  =15
####   =16
####   =17
####   =18
####   =19
####   =1A
####   =1B
####   =1C
####   =1D
####   =1E
####   =1F
#### \s =20
#### !  =21
#### &quot;  =22
#### #  =23
#### $  =24
#### =  =25
#### &amp;  =26
#### &#039;  =27
#### (  =28
#### )  =29
#### *  =2A
#### +  =2B
#### ,  =2C
#### -  =2D
#### .  =2E
#### /  =2F
#### 0  =30
#### 1  =31
#### 2  =32
#### 3  =33
#### 4  =34
#### 5  =35
#### 6  =36
#### 7  =37
#### 8  =38
#### 9  =39
#### :  =3A
#### ;  =3B
#### &lt;  =3C
#### =  =3D
#### &gt;  =3E
#### ?  =3F
#### @  =40
#### A  =41
#### B  =42
#### C  =43
#### D  =44
#### E  =45
#### F  =46
#### G  =47
#### H  =48
#### I  =49
#### J  =4A
#### K  =4B
#### L  =4C
#### M  =4D
#### N  =4E
#### O  =4F
#### P  =50
#### Q  =51
#### R  =52
#### S  =53
#### T  =54
#### U  =55
#### V  =56
#### W  =57
#### X  =58
#### Y  =59
#### Z  =5A
#### [  =5B
#### \  =5C
#### ]  =5D
#### ^  =5E
#### _  =5F
#### `  =60
#### a  =61
#### b  =62
#### c  =63
#### d  =64
#### e  =65
#### f  =66
#### g  =67
#### h  =68
#### i  =69
#### j  =6A
#### k  =6B
#### l  =6C
#### m  =6D
#### n  =6E
#### o  =6F
#### p  =70
#### q  =71
#### r  =72
#### s  =73
#### t  =74
#### u  =75
#### v  =76
#### w  =77
#### x  =78
#### y  =79
#### z  =7A
#### {  =7B
#### |  =7C
#### }  =7D
#### ~  =7E
####   =7F
#### _  =80
#### _  =81
#### &#039;  =82
#### _  =83
#### &quot;  =84
#### :  =85
#### +  =86
#### +  =87
#### _  =88
#### %  =89
#### _  =8A
#### &lt;  =8B
#### _  =8C
#### _  =8D
#### _  =8E
#### _  =8F
#### _  =90
#### &#039;  =91
#### &#039;  =92
#### &quot;  =93
#### &quot;  =94
####   =95
#### -  =96
#### -  =97
#### _  =98
#### T  =99
#### _  =9A
#### &gt;  =9B
#### _  =9C
#### _  =9D
#### _  =9E
#### _  =9F
#### а  =A0
#### б  =A1
#### в  =A2
#### _  =A3
#### д  =A4
#### _  =A5
#### ж  =A6
#### з  =A7
#### и  =A8
#### c  =A9
#### к  =AA
#### &lt;  =AB
#### м  =AC
#### -  =AD
#### R  =AE
#### п  =AF
#### &amp;#9617;  =B0
#### +  =B1
#### _  =B2
#### _  =B3
#### _  =B4
#### ў  =B5
#### &amp;#9570;  =B6
#### &amp;#9558;  =B7
#### &amp;#9557;  =B8
#### &amp;#9571;  =B9
#### &amp;#9553;  =BA
#### &gt;  =BB
#### _  =BC
#### _  =BD
#### _  =BE
#### &amp;#9488;  =BF
#### &amp;#9492;  =C0
#### &amp;#9524;  =C1
#### &amp;#9516;  =C2
#### &amp;#9500;  =C3
#### &amp;#9472;  =C4
#### &amp;#9532;  =C5
#### &amp;#9566;  =C6
#### &amp;#9567;  =C7
#### &amp;#9562;  =C8
#### &amp;#9556;  =C9
#### &amp;#9577;  =CA
#### &amp;#9574;  =CB
#### &amp;#9568;  =CC
#### &amp;#9552;  =CD
#### &amp;#9580;  =CE
#### &amp;#9575;  =CF
#### &amp;#9576;  =D0
#### &amp;#9572;  =D1
#### &amp;#9573;  =D2
#### &amp;#9561;  =D3
#### &amp;#9560;  =D4
#### &amp;#9554;  =D5
#### &amp;#9555;  =D6
#### &amp;#9579;  =D7
#### &amp;#9578;  =D8
#### &amp;#9496;  =D9
#### &amp;#9484;  =DA
#### &amp;#9608;  =DB
#### &amp;#9604;  =DC
#### &amp;#9612;  =DD
#### &amp;#9616;  =DE
#### &amp;#9600;  =DF
#### р  =E0
#### с  =E1
#### т  =E2
#### у  =E3
#### ф  =E4
#### х  =E5
#### ц  =E6
#### ч  =E7
#### ш  =E8
#### щ  =E9
#### ъ  =EA
#### ы  =EB
#### ь  =EC
#### э  =ED
#### ю  =EE
#### я  =EF
#### Ё  =F0
#### ё  =F1
#### Є  =F2
#### є  =F3
#### Ї  =F4
#### ї  =F5
#### Ў  =F6
#### ў  =F7
#### °  =F8
#### &amp;#8729;  =F9
#### ·  =FA
#### &amp;#8730;  =FB
#### №  =FC
#### ¤  =FD
#### &amp;#9632;  =FE
####    =FF</code></pre></div>]]></content>
			<author>
				<name><![CDATA[smaharbA]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=2911</uri>
			</author>
			<updated>2012-10-09T15:48:01Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=64665#p64665</id>
		</entry>
</feed>
