1. [OT] Using DIR (CMD) with redirection to a file

Hi,

Norway uses the same letters as in English alphabet, with the addition to 3 extra letters - ÆØÅ.

When I try to use the DIR (Console, Windows) command with redirection to file output instead of screen, these letters come out garbled. The letters are shown correctly when displayed directly on screen.

This is the parameters I use in the DIR command;

@dir /n /a /ogen /q /tc
GDC-VNAS-A12.res.no.enterdir.com\A12_PRO01\13079\shared\*.* >C:\WINDOWS\Profiles\111951\desktop\Shared_area_changes.txt

Does anyone know how I can keep the letters intact when redirecting the DIR output to a file?

Kenneth / ZNorQ

new topic     » topic index » view message » categorize

2. Re: [OT] Using DIR (CMD) with redirection to a file

znorq2 said...

Hi,

Norway uses the same letters as in English alphabet, with the addition to 3 extra letters - ÆØÅ.

When I try to use the DIR (Console, Windows) command with redirection to file output instead of screen, these letters come out garbled. The letters are shown correctly when displayed directly on screen.

This is the parameters I use in the DIR command;

@dir /n /a /ogen /q /tc
GDC-VNAS-A12.res.no.enterdir.com\A12_PRO01\13079\shared\*.* >C:\WINDOWS\Profiles\111951\desktop\Shared_area_changes.txt

Does anyone know how I can keep the letters intact when redirecting the DIR output to a file?

Kenneth / ZNorQ

How are you displaying the file? What makes you think it is garbled? Are you using Notepad or Wordpad to open it?

If you redirect the listing to a file, and then display the contents of that file on the same console using "type C:\WINDOWS\Profiles\111951\desktop\Shared_area_changes.txt", are the results still garbled?

This sounds like a file text encoding issue.

new topic     » goto parent     » topic index » view message » categorize

3. Re: [OT] Using DIR (CMD) with redirection to a file

jimcbrown said...
znorq2 said...

Hi,

Norway uses the same letters as in English alphabet, with the addition to 3 extra letters - ÆØÅ.

When I try to use the DIR (Console, Windows) command with redirection to file output instead of screen, these letters come out garbled. The letters are shown correctly when displayed directly on screen.

This is the parameters I use in the DIR command;

@dir /n /a /ogen /q /tc
GDC-VNAS-A12.res.no.enterdir.com\A12_PRO01\13079\shared\*.* >C:\WINDOWS\Profiles\111951\desktop\Shared_area_changes.txt

Does anyone know how I can keep the letters intact when redirecting the DIR output to a file?

Kenneth / ZNorQ

How are you displaying the file? What makes you think it is garbled? Are you using Notepad or Wordpad to open it?

If you redirect the listing to a file, and then display the contents of that file on the same console using "type C:\WINDOWS\Profiles\111951\desktop\Shared_area_changes.txt", are the results still garbled?

This sounds like a file text encoding issue.

I usually use Notepad, but I tried viewing them in Wordpad too. The letters are replaced with the following characters; ‘›†’

Interesting enough, I followed your tip and TYPED the content of the file in the console; The chars are now shown properly again.

I agree with you on the text coding issue, but I've no clue how to go about getting it fixed.

Kenneth / ZNorQ

new topic     » goto parent     » topic index » view message » categorize

4. Re: [OT] Using DIR (CMD) with redirection to a file

znorq2 said...

Hi,

Norway uses the same letters as in English alphabet, with the addition to 3 extra letters - ÆØÅ.

When I try to use the DIR (Console, Windows) command with redirection to file output instead of screen, these letters come out garbled. The letters are shown correctly when displayed directly on screen.

Have you tried changing the codepage? Not sure how this might work with redirection. What are the bytes of the file? The file may be correct, but the viewer you're using may be trying a different encoding. Read the file in binary mode, and see if the bytes are what you expected.

Matt

new topic     » goto parent     » topic index » view message » categorize

5. Re: [OT] Using DIR (CMD) with redirection to a file

znorq2 said...
jimcbrown said...
znorq2 said...

Hi,

Norway uses the same letters as in English alphabet, with the addition to 3 extra letters - ÆØÅ.

When I try to use the DIR (Console, Windows) command with redirection to file output instead of screen, these letters come out garbled. The letters are shown correctly when displayed directly on screen.

This is the parameters I use in the DIR command;

@dir /n /a /ogen /q /tc
GDC-VNAS-A12.res.no.enterdir.com\A12_PRO01\13079\shared\*.* >C:\WINDOWS\Profiles\111951\desktop\Shared_area_changes.txt

Does anyone know how I can keep the letters intact when redirecting the DIR output to a file?

Kenneth / ZNorQ

How are you displaying the file? What makes you think it is garbled? Are you using Notepad or Wordpad to open it?

If you redirect the listing to a file, and then display the contents of that file on the same console using "type C:\WINDOWS\Profiles\111951\desktop\Shared_area_changes.txt", are the results still garbled?

This sounds like a file text encoding issue.

I usually use Notepad, but I tried viewing them in Wordpad too. The letters are replaced with the following characters; ‘›†’�

Interesting enough, I followed your tip and TYPED the content of the file in the console; The chars are now shown properly again.

I agree with you on the text coding issue, but I've no clue how to go about getting it fixed.

Kenneth / ZNorQ

Hmm. My browser can't display those characters. In vi I see

<91><9b><86><92><9d> 

Anyways, my recommendation is to use a different program to view and edit these text files. The only way I know to change the text encoding used to decode these files is Format->Font->Script in Notepad (change from Western to something else) and Format->Font->Script in Wordpad (change from Western to something else).

The issue isn't the file itself, but in the program you use to view it.

new topic     » goto parent     » topic index » view message » categorize

6. Re: [OT] Using DIR (CMD) with redirection to a file

mattlewis said...
znorq2 said...

Hi,

Norway uses the same letters as in English alphabet, with the addition to 3 extra letters - ÆØÅ.

When I try to use the DIR (Console, Windows) command with redirection to file output instead of screen, these letters come out garbled. The letters are shown correctly when displayed directly on screen.

Have you tried changing the codepage? Not sure how this might work with redirection. What are the bytes of the file? The file may be correct, but the viewer you're using may be trying a different encoding. Read the file in binary mode, and see if the bytes are what you expected.

Matt

Hi, Matt.

The current code page is 850.

Tried the following;

  1. Created a new test directory.
  2. Created a folder called "æøåÆØÅ"
  3. Opened console (cmd)
  4. CD'd to the test directory.
  5. CHCP 865 (Nordic)
  6. dir *.* /b >files.txt
  7. Content of "files.txt";
    1. files.txt
    2. ‘›†’
  8. Content presented in hex;
    1. 66,69,6C,65,73,2E,74,78,74,
    2. 0D,0A,
    3. 91,9B,86,92,9D,8F,
    4. 0D,0A
new topic     » goto parent     » topic index » view message » categorize

7. Re: [OT] Using DIR (CMD) with redirection to a file

UUps, this didn't come out like I wanted... :(

new topic     » goto parent     » topic index » view message » categorize

8. Re: [OT] Using DIR (CMD) with redirection to a file

znorq2 said...

UUps, this didn't come out like I wanted... :(

Fixed it for you. You can use the triple brackets {{{/}}} to print output literally.

-Greg

new topic     » goto parent     » topic index » view message » categorize

9. Re: [OT] Using DIR (CMD) with redirection to a file

znorq2 said...

Hi, Matt.

The current code page is 850.

Ok, it definitely sounds like the issue is with the file you're using to view the output. I ran this:

 sequence s = {#66,#69,#6C,#65,#73,#2E,#74,#78,#74, #0D,#0A, 
 	#91,#9B,#86,#92,#9D,#8F, #0D,#0A  } 
  
 puts(1, s ) 

...and got the expected output:

files.txt 
æøåÆØÅ 

So the file appears to be correct.

Matt

new topic     » goto parent     » topic index » view message » categorize

10. Re: [OT] Using DIR (CMD) with redirection to a file

Hi znorq2,

In file names and commands Windows uses the OEM (DOS) encoding,
but in .txt and other text files the native Windows encoding.

In Russian OEM is cp866, Windows - cp1251.

I recode my DIR output from 866 to 1251 to read it in Notepad properly.

Regards,
kinz

new topic     » goto parent     » topic index » view message » categorize

11. Re: [OT] Using DIR (CMD) with redirection to a file

kinz said...

Hi znorq2,

In file names and commands Windows uses the OEM (DOS) encoding,
but in .txt and other text files the native Windows encoding.

In Russian OEM is cp866, Windows - cp1251.

I recode my DIR output from 866 to 1251 to read it in Notepad properly.

Or just use in Notepad the Terminal font.

Regards,
kinz

new topic     » goto parent     » topic index » view message » categorize

12. Re: [OT] Using DIR (CMD) with redirection to a file

ghaberek said...
znorq2 said...

UUps, this didn't come out like I wanted... :(

Fixed it for you. You can use the triple brackets {{{/}}} to print output literally.

-Greg

Ok, thanks Greg - but does that include the slash - "/"?

kinz said...
kinz said...

Hi znorq2,

In file names and commands Windows uses the OEM (DOS) encoding,
but in .txt and other text files the native Windows encoding.

In Russian OEM is cp866, Windows - cp1251.

I recode my DIR output from 866 to 1251 to read it in Notepad properly.

Or just use in Notepad the Terminal font.

Regards,
kinz

Hi kinz,

When opening the console, default code page is 850. According to this page sent to me earlier, 865 (Nordic) is probably the one I should change to before running the DIR command...

This is what I did;

  1. Created folder "æøåÆØÅ" under "c:\data\test".
  2. Opened console (cmd)
  3. Changed to "c:\data\test"
  4. Confirmed current code page 850 (using chcp w/o params.)
  5. chcp 865
  6. dir *.* /b > files.txt
  7. Opened "files.txt" using notepad.
  8. Changed to font to "Terminal".


Letters "æøåÆØÅ" are now visible.

I use Font "Lucida Console" / Script "Western" as a default (did a little research, and this is the default font/script setting for everybody..), and æøåÆØÅ is perfectly usable characters in this font. But, when æøåÆØÅ is routed through DIR's redirection, it becomes garbled. Apperantly, they have a different byte representation in Western script compared to OEM/DOS? If so, it seems I have to go through the file replacing it with the correct byte representation for "Lucidia Concole / Western", (which shouldn't really be a problem..)?

That said, I would have used Euphoria - and not Console/DIR, but I've got no idea how I can produce the information I'm after (with the exception of path/filename, ofcourse);

  1. Created date/time
  2. Created by
  3. Filename/path


Kenneth / ZNorQ

new topic     » goto parent     » topic index » view message » categorize

13. Re: [OT] Using DIR (CMD) with redirection to a file

znorq2 said...

Hi kinz,

When opening the console, default code page is 850. According to this page sent to me earlier, 865 (Nordic) is probably the one I should change to before running the DIR command...

Your default code page 850 seems to be namely OEM (DOS) code page, but cp865 seems to be some code page with win-1252 encoding for "æøåÆØÅ" letters.

The DIR command uses strongly OEM encoding.

znorq2 said...

This is what I did;

  1. Created folder "æøåÆØÅ" under "c:\data\test".
  2. Opened console (cmd)
  3. Changed to "c:\data\test"
  4. Confirmed current code page 850 (using chcp w/o params.)
  5. chcp 865

Try the chcp w/o params to see if cp was changed to 865 really.

znorq2 said...
  1. dir *.* /b > files.txt
  2. Opened "files.txt" using notepad.
  3. Changed to font to "Terminal".

OK, Terminal has strongly OEM encoding.

znorq2 said...


Letters "æøåÆØÅ" are now visible.

So, DIR worked in OEM (850).

znorq2 said...

I use Font "Lucida Console" / Script "Western" as a default (did a little research, and this is the default font/script setting for everybody..), and æøåÆØÅ is perfectly usable characters in this font. But, when æøåÆØÅ is routed through DIR's redirection, it becomes garbled. Apperantly, they have a different byte representation in Western script compared to OEM/DOS? If so, it seems I have to go through the file replacing it with the correct byte representation for "Lucidia Concole / Western", (which shouldn't really be a problem..)?

"Lucida Console" has Windows encoding 1251 here, in Russia, so yours one works same way, on cp1252, and can not display OEM text properly, I think.

I use recoding to write and read Russian file names in EU.
The ed editor works as OEM thing, so recodind is not needed, but if I program in, say, Notepad or Edita or such a Windows editor, I need recode from 1251 to 866 the file names and Russian output of DIR, if I want to read output in Notepad or Edita without changeing the font to Terminal.

znorq2 said...

That said, I would have used Euphoria - and not Console/DIR, but I've got no idea how I can produce the information I'm after (with the exception of path/filename, ofcourse);

  1. Created date/time
  2. Created by
  3. Filename/path

Try the function below, it is not tested, but gives the idea, I hope.

constant W = {#E6,#F8,#E5,#C6,#D8,#C5}, -- codes of your letters in 1252 
         O = {#91,#9B,#86,#92,#9D,#8F}, -- codes of same letters in 850 
    W_to_O = 1, -- mode from Windows to OEM 
    O_to_W = 2  -- mode from OEM to Windows 
 
function recode_nor(sequence input, -- input text (command or DIR output) 
                      integer mode) -- W_to_O, or O_to_W 
integer c, d 
  for i=1 to length(input) do 
     c = input[i] 
       if mode = W_to_O then 
           d = find(c, W) 
             if d then 
                 input[i]= O[d] 
             end if 
       end if 
       if mode = O_to_W then 
           d = find(c, O) 
             if d then 
                 input[i]= W[d] 
             end if 
       end if 
   end for 
  return input 
end function 


Regards,
kinz

new topic     » goto parent     » topic index » view message » categorize

14. Re: [OT] Using DIR (CMD) with redirection to a file

You could try this. Before running the dir command, create another instance of the command shell like this:

cmd /u

This instructs cmd to use Unicode when redirecting to a pipe or file.

Not sure if this will solve your problem, but it is worth a try.

new topic     » goto parent     » topic index » view message » categorize

15. Re: [OT] Using DIR (CMD) with redirection to a file

krg said...

You could try this. Before running the dir command, create another instance of the command shell like this:

cmd /u

This instructs cmd to use Unicode when redirecting to a pipe or file.

Not sure if this will solve your problem, but it is worth a try.


krg, that worked! Used the following syntax to achieve the goal;

@cmd /u /c dir *.* /b >myfiles.txt

Extend my gratitude to all who's been kind enough trying to help me out..

PS! Apologies for not responding earlier, have very busy schedule..

Regards, Kenneth / ZNorQ

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu