Assuming I have fonts installed which have the appropriate glyphs in them, is there a command shell for Windows XP that will display Unicode characters? At a minimum, two things that should display Unicode correctly:
Directory listings. I don't care what I have to type (dir, ls, get-childitem, etc.), so long as files with Unicode characters in their names appear with the right glyphs, not the unprintable character box.
Text file content listings. Again, doesn't matter to me if it's 'less', 'more', 'cat', 'dog', etc., so long as the characters are printed. I recognize that this is more complicated because of character encoding of the file, so if I have to specify that on the command line that's fine with me.
Here's what I've tried so far:
cmd.exe
Windows PowerShell; including the multilingual version.
Cygwin bash
No luck. I even tried installing custom fonts for cmd/PowerShell. PowerShell and cmd.exe seem to be Unicode-aware in the sense that I can copy/paste the non-printable box out of there and it will paste into other apps with the correct characters. Cygwin (?) seems to convert to the ? character and that comes through in the copy/paste.
Any ideas?
To do this with cmd.exe, you'll need to use the console properties dialog to switch to a Unicode TrueType font.
Then use these commands:
CHCP 65001
DIR > UTF8.TXT
TYPE UTF8.TXT
Commands:
Switch console to UTF-8 (65001)
Redirect output of DIR to UTF8.TXT
Dump UTF-8 to console
The characters will still need to be supported by the font to display properly on the console.
I18N: Unicode at the Windows command prompt (C++; .Net; Java)
This was a major issue in PowerShell v1. Version 2 is shipping with a "graphical shell" that corrects the problem, which is ultimately not with PowerShell, but with the Windows console host (which Cmd.exe also uses). You can get the current CTP for PowerShell v2, if you want.
Actually, PowerShell v2.0 was finalized and shipped with the release of Windows 7 and Windows Server 2008 R2 in early August. In addition, the backported versions (Windows Vista/2008) reached their Release Candidate milestone just the other day; Windows XP/Windows Server 2003 should follow very shortly. Linky linky.
Setting the codepage to UTF-8 with the command "chcp 65001" should help you print file contents correctly to the shell (using cmd.exe). This won't work for directory listings though (UTF-16 encoding in NTFS file names).
Try this:
powershell.exe -NoExit /c "chcp.com 65001"
Who uses msysgit:
powershell.exe -NoExit /c "chcp.com 65001; sh --login -i"
Do not forget to change font of window to TrueType font with UTF-8 support ("Lucida Console")
This is how I can got Chinese output in cmd.exe running on Windows 7 Pro English Version. I also tried file names with Japanese, Russian, and Polish and they all seem to display correctly. Input also seems to work, at least when I tried to do a dir xxx* containing non-ascii characters.
Install console2, which is a front-end to cmd.exe (and other shells)
After installation, follow these instructions
Delete the key HKEY_CURRENT_USER\Console\Console2 command window in the registry.
Import the following data into windows registry:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Console\Console2 command window]
"CodePage"=dword:000003a8
"FontSize"=dword:000a0000
"FontFamily"=dword:00000036
"FontWeight"=dword:00000190
"FaceName"="細明體"
"HistoryNoDup"=dword:00000000
You may or may not have to change the font. Initially I had the font set to #NimSum, and the Chinese characters came out rotated 90 degrees. Then I switched to NimSum (without the #) and it came out correctly. Then just out of curiosity I switched to Consola and yet I can still see the Chinese characters. So I'm not sure if you actually have to set the font or not.
For a true shell, try PowerShell Plus. You can select Unicode fonts and work with other languages, not only in the editor, but in the true console.
Try Console 2. Be careful with the colors/palette configurations though. Those are a bit buggy. I have confirmed them to not work; they behave like cmd.exe.
Open an elevated command prompt (run cmd as administrator). Query your registry for available TrueType fonts to the console by:
REG query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont"
You'll see an output like:
0 REG_SZ Lucida Console
00 REG_SZ Consolas
936 REG_SZ *新宋体
932 REG_SZ *MS ゴシック
Now we need to add a TrueType font that supports the characters you need like Courier New, we do this by adding zeros to the string name, so in this case the next one would be "000" :
REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont" /v 000 /t REG_SZ /d "Courier New"
Now we implement UTF-8 support:
REG ADD HKCU\Console /v CodePage /t REG_DWORD /d 65001 /f
Set default font to "Courier New":
REG ADD HKCU\Console /v FaceName /t REG_SZ /d "Courier New" /f
Set font size to 20 :
REG ADD HKCU\Console /v FontSize /t REG_DWORD /d 20 /f
Enable quick edit if you like :
REG ADD HKCU\Console /v QuickEdit /t REG_DWORD /d 1 /f
As of November 2011, MinTTY is now Cygwin's default terminal emulator (installed by setup.exe). MinTTY is a fork of PuTTY's terminal emulator, and as such sports proper Unicode support and much-improved compatibility with other terminal emulators.
PowerShell V2 CTP3 inside Console2 seems to do that. The only downside is that the default console encoding is UCS-2 LE instead of UTF-8.
Also from
UTF-16 on cmd.exe
Open/run cmd.exe
Click on the icon at the top-left corner
Select properties
Then "Font" bar
Select "Lucida Console" and OK.
Write Chcp 10000 at the prompt
Finally dir /b
A fast and convenient way to do it is on the Explorer.
1. Open the Explorer window.
2. Traverse to the top level of directory where you want to find.
3. On the upper right corner, there is a find field.
Related
Trying to get an output through cmd with the list of folders and files inside a drive.
Some folders are written in cyrillic alphabet so I only get ??? symbols.
My command:
tree /f /a |clip
or
tree /f /a >output.txt
Result:
\---???????????
\---2017 - ????? ??????? ????
01. ?????.mp3
02. ? ???????.mp3
03. ????.mp3
04. ?????? ? ???.mp3
05. ?????.mp3
06. ???? ?????.mp3
07. ???????? ????.mp3
08. ??? ?? ?????.mp3
Cover.jpg
Any idea?
tree.com uses the native UTF-16 encoding when writing to the console, just like cmd.exe and powershell.exe. So at first you'd expect redirecting the output to a file or pipe to also use Unicode. But tree.com, like most command-line utilities, encodes output to a pipe or disk file using a legacy codepage. (Speaking of legacy, the ".com" in the filename here is historical. In 64-bit Windows it's a regular 64-bit executable, not 16-bit DOS code.)
When writing to a pipe or disk file, some programs hard code the system ANSI codepage (e.g. 1252 in Western Europe) or OEM codepage (e.g. 850 in Western Europe), while some use the console's current output codepage (if attached to a console), which defaults to OEM. The latter would be great because you can change the console's output codepage to UTF-8 via chcp.com 65001. Unfortunately tree.com uses the OEM codepage, with no option to use anything else.
cmd.exe, on the other hand, at least provides a /u option to output its built-in commands as UTF-16. So, if you don't really need tree-formatted output, you could simply use cmd's dir command. For example:
cmd /u /c "dir /s /b" | clip
If you do need tree-formatted output, one workaround would be to read the output from tree.com directly from a console screen buffer, which can be done relatively easily for up to 9,999 lines. But that's not generally practical.
Otherwise PowerShell is probably your best option. For example, you could modify the Show-Tree script to output files in addition to directories.
I am trying to redirect a PS output to a file and process it further.
For this I am using the Printer Port Redirection RedMon which is sending the output to CMD.exe
C:\Windows\system32\cmd.exe
As arguments I expected that something like the following should work, but it does not. "%1" contains the user input for filename.
/c >"%1"
or
/c 1>"%1"
or
/c |"%1"
or
/c > "%1" 2>&1
What almost works if I send the output to a batch file which writes it then to file.
/c WriteOutput.bat "%1"
However, the batch file is somehow altering the file (skipping empty lines, and ignoring exclamation marks and so on...)
If possible I want to avoid a batch file. Is there a way to get it "directly" to a file?
Select "Print to FILE" in the printer options is not an option for me. I want the same end result but via cmd.exe being able to process it further.
Any ideas?
Edit:
Well, that's the batch file I used. It neglects empty lines and space at the beginning.
#echo off
setlocal
set FileName=%1
echo(>%FileName%.ps
for /F "tokens=*" %%A in ('more') do (
echo %%A>>%FileName%.ps
)
Well, so far I still haven't found a direct way to write STDIN via RedMon via CMD.exe to a file. As #aschipfl wrote, all the versions with for /F will skip lines and ignore certain characters.
However, with the following batch script (via RedMon) I end up with a "correct looking" file on disk.
C:\Windows\system32\cmd.exe /c WritePS.bat "%1"
"%1" contains the user input for filename without extension.
The Batch-File WritePS.bat looks as simple as this:
#echo off & setlocal
set FileName=%1.ps
more > "%FileName%"
However,
the resulting Postscript file is different from a file which I "Print to FILE" via the Postscript-Printer setup. I am pretty sure that all the printer settings which I can set are the same in both cases.
If anybody has an idea why there might be a difference, please let me know.
I'm writing a script (powershell) for SQL Server 2014 Express Install.
The problem is: I have to change the OS Language (Region and languages) to fr_FR (French from France) Silently. The current language is fr_CA (French from Canada).
My question is: Can i change the language from intl.cpl (Region and languages) with a batch file or command line or just from the register?
Thank you
This could be as simple as one line command in PowerShell
Set-ItemProperty 'HKCU:\Control Panel\Desktop' -Name "PreferredUILanguages" -Value 'fr-FR'
Alternatively you could use a .reg file, or batch file calling reg.exe like this
reg add "HKCU:\Control Panel\Desktop" /f /v "PreferredUILanguages" /t REG_SZ /d 'fr-FR'
Ref: Change OS Language using PowerShell
didn't work for me but i found a solution to my problem.
I use a XML file to change properties by executing :
control.exe intl.cpl,,/f:"c:\Unattend.xml"
in CMD.exe as Admin
Here is my XML file :
<gs:GlobalizationServices xmlns:gs="urn:longhornGlobalizationUnattend">
<gs:UserList>
<gs:User UserID="Current"/>
</gs:UserList>
<!-- user locale -->
<gs:UserLocale>
<gs:Locale Name="fr-FR" SetAsCurrent="true" ResetAllSettings="false">
</gs:Locale>
</gs:UserLocale>
</gs:GlobalizationServices>
Thanks for helping
To change windows 7 language
Open the Control Panel.
Snap the "View by" menu and select "Huge symbols" or "Little symbols".
Select Windows Update.
Snap the "# discretionary updates are accessible" interface
Check the container for the language you need to download.
Snap the. Install refreshes.
Come back to the Control Panel and select "District and Language".
Select the language you just introduced from the "Pick a presentation language" drop-down menu.
Snap.Apply
Change your framework area if the language isn't showing in certain projects.
You can also visit
[url=https://www.morphigo.com/]https://www.morphigo.com/[/url]
I have a need to use the DOS command FINDSTR to search in all our source code files mixed with other types of files such as PDF, exe, dll, etc.
I do not need to search those binary files. Is there a way to exclude binary files?
My command looks like
findstr /r /n /o /s /g:c:\projects\vsssearch\muafinddata.txt /d:c:/projects/axl *.axl > output.txt
Thanks in advance for any insight.
John
Do yo try /p? Help says: "/P Skip files with non-printable characters."
I have a little c# console program that outputs some text using Console.WriteLine. I then pipe this output into a textfile like:
c:myprogram > textfile.txt
However, the file is always an ansi text file, even when I start cmd with the /u switch.
cmd /? says about the /u switch:
/U Causes the output of internal
commands to a pipe or file to be Unicode
And it indeed makes a difference, when I do an
c:echo "foo" > text.txt
the text.txt is unicode (without BOM)
I wonder why piping the output of my console program into a new file does not create an unicode file likewise and how i could change that?
I just use Windows Power Shell (which produces a unicode file with correct BOM), but I'd still like to know how to do it with cmd.
Thanks!
The /U switch, as the documentation says, affects whether internal commands generate Unicode output. Your program is not one of cmd.exe's internal commands, so the /U option does not affect it.
To create a Unicode text file, you need to make sure your program is generating Unicode text.
Even that may not be enough, though. I came across this blog from Junfeng Zhang describing how to write Unicode text in a console program. It checks the file type of the standard output handle. For character files (a console or LPT port), it calls WriteFileW. For all other types of handles (including disk files and pipes), it converts the output string to the console's current code page. I'm afraid I don't know how that translates into .Net terms, though.
I had a look how mscorlib implements Console.WriteLine, and it seems to decide on which text output encoding to use based on a call to GetConsoleOutPutCP. So I'm guessing (but have not yet confimed) that the codepage returned is a differnt one for a PS console than for a cmd console so that my program indeed only outputs ansi when running from cmd.