Тема: CMD/BAT: О кодировке
есть простой код (измененный для хелпа), как сделать по русски на вин 7 ? (изначально было без иконвов и приблуд)
оно все по русски, но интересует без изменения шрифта окна (т.е. все в 866)
@echo off
chcp 866 > nul
setlocal ENABLEDELAYEDEXPANSION
set findstr=true
set find=%systemroot%\system32\findstr.exe
set ScriptFullName=%~0
set ScriptName=%~nx0
if not exist "%find%" (
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
"%gpg.exe%" --no-verbose --batch --no-tty --list-secret-keys --with-colons --fixed-list-mode > "%appdata%\gpgshell\~seckeys.dat"
"%gpg.exe%" --no-verbose --batch --no-tty --list-config --with-colons > "%appdata%\gpgshell\~pubkeys.dat"
echo.>>"%appdata%\~pubkeys.dat"
"%gpg.exe%" --no-verbose --batch --no-tty --list-public-keys --with-fingerprint --with-colons --fixed-list-mode >> "%appdata%\gpgshell\~pubkeys.dat"
set rcpt=
set z=
set /a n=-1
for /f "tokens=1,2,3,4,5* delims=:" %%a in ('find "uid:" ^< "%~dp0~pubkeys.dat"') 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 "%~1" (
echo q. Exit
set /a quit=!n! + 1
choice /c !z!q /m "Выберите ключ"
) else (cd>nul)
set /a n=!ERRORLEVEL! - 1
if %n% equ %quit% (
echo.
exit /b 255
)
for /f "tokens=1,2,3,4,5* delims=:" %%a in ('find "pub:" ^< "%~dp0~pubkeys.dat"') do (
if !n! equ 0 set key=%key%%%~e
set /a n-=1
)
if not "%key%"=="0x" (
chcp 1251 > nul
chcp 1251|"%gpg.exe%" -v -o "%~1.gpg" -r %key% -e "%~1" 2> nul
) else (
echo.
echo Press any key to Help...
pause > nul
"%gpg.exe%" --help > %temp%\gpghelp.txt
call :iconv cp1251 cp866 %temp%\gpghelp.txt
type "!iconv!"
echo Press any key...
pause > nul
)
endlocal
chcp 866 > nul
exit /b
:iconv (from,to,input) {
@@rem Процедура коневертации кодировок, через файл для универсальности
@@rem
setlocal
chcp 866> nul
set out=%~0
if "%out:~0,1%"==":" (
set out=%out:~1%
) else (
set out=out
)
if /i "%~1"=="utf8" (
set code=65001
) else if /i "%~1"=="utf-8" (
set code=65001
) else if /i "%~1"=="cp1251" (
set code=1251
) else if /i "%~1"=="cp866" (
set code=866
) else if /i "%~1"=="iso-8859-5" (
set code=28595
) else if /i "%~1"=="koi8-r" (
set code=20866
) else if not "%~1"=="" (
set code=%~1
) else (
set code=1251
)
if /i "%~2"=="utf8" (
set tocode=65001
) else if /i "%~2"=="utf-8" (
set tocode=65001
) else if /i "%~2"=="cp1251" (
set tocode=1251
) else if /i "%~2"=="cp866" (
set tocode=866
) else if /i "%~2"=="iso-8859-5" (
set tocode=28595
) else if /i "%~2"=="koi8-r" (
set tocode=20866
) else if not "%~2"=="" (
set tocode=%~2
) else (
set tocode=1251
)
set outtype=file
set utf16=%temp%\%RANDOM%.utf-16
set ftemp=%temp%\%RANDOM%.%code%
if exist "%~3" (
set stream=type "%~3"
) else (
set outtype=var
set string="%~3"
set string=!string:^|=^^^|!
echo !string:~1,-1!> "%ftemp%"
set stream=type "%ftemp%"
)
call :getfileinfo path "%ScriptFullName%"
if exist "%getfileinfo%\iconv\iconv.exe" (
%stream%| "%getfileinfo%\iconv\iconv.exe" -f %~1 -t %~2 > "%ftemp%.%tocode%"
goto end_iconv
)
call :getchar "%ScriptFullName%" "=FF"
set "mark=%getchar%"
call :getchar "%ScriptFullName%" "=FE"
set "mark=%mark%%getchar%"
chcp 866 > nul
echo.%mark%>> %utf16%
chcp %tocode% > nul
chcp %code% |>> "%utf16%" cmd /u /c "%stream% & chcp %tocode% > nul"
chcp %tocode% > nul
type "%utf16%" > "%ftemp%.%tocode%"
:end_iconv
chcp 866 > nul
set ret=%ftemp%.%tocode%
if /i "%outtype%"=="var" (
for /f "delims=" %%i in ('type "%ftemp%.%tocode%"') do (
set ret=%%i
)
del /q "%ftemp%.%tocode%"
)
if exist "%ftemp%" del /q "%ftemp%"
rem if exist "%utf16%" del /q "%utf16%"
endlocal & set %out%=%ret%
exit /b 0
}
:getfileinfo (info,filepath) {
@@rem Процедура получения свойств файла
@@rem
setlocal
set out=%~0
if "%out:~0,1%"==":" (
set out=%out:~1%
) else (
set out=out
)
set info=undefined
set opt=%~1
if /i "%opt%"=="name" (
set info=%~n2
) else if /i "%opt%"=="ext" (
set info=%~x2
) else if /i "%opt%"=="fname" (
set info=%~nx2
) else if /i "%opt%"=="fpath" (
set info=%~f2
) else if /i "%opt%"=="spath" (
set info=%~s2
) else if /i "%opt%"=="size" (
set /a info=0
set /a info=%~z2 2> nul
) else if /i "%opt%"=="drive" (
set info=%~d2
) else if /i "%opt%"=="folder" (
set info=%~p2
) else if /i "%opt%"=="path" (
set info=%~dp2
)
set /a ret=1
if exist "%~2" set /a ret=0
endlocal & set %out%=%info%
exit /b %ret%
}
:getchar (table,asc) {
@@rem Процедура получения нужного символа по коду
@@rem
setlocal
set out=%~0
if "%out:~0,1%"==":" (
set out=%out:~1%
) else (
set out=out
)
set char=
set table=%~1
set asc=%~2
for /f "tokens=2" %%u in ('%find%"####" "%table%" ^| %find%"%asc%"') do (
set "char=%%~u"
)
endlocal & set "%out%=%char%"
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
#### ╢ =14
#### з =15
#### =16
#### =17
#### =18
#### =19
#### =1A
#### =1B
#### =1C
#### =1D
#### =1E
#### =1F
#### \s =20
#### ! =21
#### " =22
#### # =23
#### $ =24
#### = =25
#### & =26
#### ' =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
#### < =3C
#### = =3D
#### > =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
#### ' =82
#### _ =83
#### " =84
#### : =85
#### + =86
#### + =87
#### _ =88
#### % =89
#### _ =8A
#### < =8B
#### _ =8C
#### _ =8D
#### _ =8E
#### _ =8F
#### _ =90
#### ' =91
#### ' =92
#### " =93
#### " =94
#### =95
#### - =96
#### - =97
#### _ =98
#### T =99
#### _ =9A
#### > =9B
#### _ =9C
#### _ =9D
#### _ =9E
#### _ =9F
#### а =A0
#### б =A1
#### в =A2
#### _ =A3
#### д =A4
#### _ =A5
#### ж =A6
#### з =A7
#### и =A8
#### c =A9
#### к =AA
#### < =AB
#### м =AC
#### - =AD
#### R =AE
#### п =AF
#### ░ =B0
#### + =B1
#### _ =B2
#### _ =B3
#### _ =B4
#### ў =B5
#### ╢ =B6
#### ╖ =B7
#### ╕ =B8
#### ╣ =B9
#### ║ =BA
#### > =BB
#### _ =BC
#### _ =BD
#### _ =BE
#### ┐ =BF
#### └ =C0
#### ┴ =C1
#### ┬ =C2
#### ├ =C3
#### ─ =C4
#### ┼ =C5
#### ╞ =C6
#### ╟ =C7
#### ╚ =C8
#### ╔ =C9
#### ╩ =CA
#### ╦ =CB
#### ╠ =CC
#### ═ =CD
#### ╬ =CE
#### ╧ =CF
#### ╨ =D0
#### ╤ =D1
#### ╥ =D2
#### ╙ =D3
#### ╘ =D4
#### ╒ =D5
#### ╓ =D6
#### ╫ =D7
#### ╪ =D8
#### ┘ =D9
#### ┌ =DA
#### █ =DB
#### ▄ =DC
#### ▌ =DD
#### ▐ =DE
#### ▀ =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
#### ∙ =F9
#### · =FA
#### √ =FB
#### № =FC
#### ¤ =FD
#### ■ =FE
#### =FF
Я конечно далек от мысли... (с)