Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show characters with accents in redirect file (>output.txt)

example

mode con: cp>%tmp%\output.tmp
notepad %tmp%\output.tmp

show:

Statut du p‚riph‚rique CON:
---------------------------
    Page de codesÿ:   850

instead of:

Statut du périphérique CON:
---------------------------
    Page de codes :   850

I also tried with chcp 65001 and 1252

Do you know a fix?

Edit:

I use the truetype Lucida fonts, and even if I do type %tmp%\output.tmp it shows the right characters in console, but not in any text editor.

I also tried:

cmd /U /C "chcp 65001>nul &mode con: cp>%tmp%\output.tmp"

and

cmd /A /C "chcp 65001>nul &mode con: cp>%tmp%\output.tmp"

without success

like image 801
Paul Avatar asked Oct 07 '15 17:10

Paul


People also ask

How do I redirect command line output to a text file?

Redirect Output from the Windows Command Line to a Text File. When you type a command on the Windows command line, the output from the command is displayed in the command prompt window. For some commands, the output can be several rows long and sometimes longer than the height of the command window, causing you to scroll to view all of the output.

What is an example of output redirection?

For example: suppose we want to run a command called “date” if we run it will print the output to the current terminal screen. But our requirement is different, we don’t want the output to be displayed on the terminal. We want the output to be saved in a file. This could be done very easily with output redirection.

How do I redirect a batch file to a single file?

When running a Batch file, the command is executed in cmd.exe. The output of these commands is obtained in two streams, i.e., standard output and standard error. These outputs can be either redirected to separate files or a single file. A redirection operator is denoted by >. By default, the cmd uses > for the standard output, the same as 1>.

What is redirection in Linux?

Redirection here simply means diverting the output or input. Similarly, if we have a command that needs input to be performed. Let take a command “head” this needs input to give output.


2 Answers

You may use the /U switch of cmd.exe in order to output Unicode characters. For example:

cmd /U /C dir > dirInUnicode.txt

However, this switch works on internal commands only, so you must use an auxiliary file in order to convert the output of mode command:

mode con: cp>%tmp%\output1.tmp
cmd /U /C type %tmp%\output1.tmp > %tmp%\output2.tmp
like image 134
Aacini Avatar answered Sep 19 '22 05:09

Aacini


Use PowerShell instead of DOS as a command line prompt. Its works flawlessly with special characters.

C:> powershell
PS C:> mode con: cp > temp.txt
PS C:> notepad temp.txt
like image 24
Frederic Avatar answered Sep 18 '22 05:09

Frederic