1. [OT] Using DIR (CMD) with redirection to a file
- Posted by znorq2 Oct 05, 2009
- 2511 views
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
2. Re: [OT] Using DIR (CMD) with redirection to a file
- Posted by jimcbrown (admin) Oct 05, 2009
- 2463 views
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.
3. Re: [OT] Using DIR (CMD) with redirection to a file
- Posted by znorq2 Oct 05, 2009
- 2476 views
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
4. Re: [OT] Using DIR (CMD) with redirection to a file
- Posted by mattlewis (admin) Oct 05, 2009
- 2488 views
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
5. Re: [OT] Using DIR (CMD) with redirection to a file
- Posted by jimcbrown (admin) Oct 05, 2009
- 2502 views
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.
6. Re: [OT] Using DIR (CMD) with redirection to a file
- Posted by znorq2 Oct 05, 2009
- 2485 views
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;
- Created a new test directory.
- Created a folder called "æøåÆØÅ"
- Opened console (cmd)
- CD'd to the test directory.
- CHCP 865 (Nordic)
- dir *.* /b >files.txt
- Content of "files.txt";
- files.txt
- ‘›†’
- Content presented in hex;
- 66,69,6C,65,73,2E,74,78,74,
- 0D,0A,
- 91,9B,86,92,9D,8F,
- 0D,0A
7. Re: [OT] Using DIR (CMD) with redirection to a file
- Posted by znorq2 Oct 05, 2009
- 2463 views
UUps, this didn't come out like I wanted... :(
8. Re: [OT] Using DIR (CMD) with redirection to a file
- Posted by ghaberek (admin) Oct 05, 2009
- 2454 views
UUps, this didn't come out like I wanted... :(
Fixed it for you. You can use the triple brackets {{{/}}} to print output literally.
-Greg
9. Re: [OT] Using DIR (CMD) with redirection to a file
- Posted by mattlewis (admin) Oct 05, 2009
- 2464 views
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
10. Re: [OT] Using DIR (CMD) with redirection to a file
- Posted by kinz Oct 05, 2009
- 2453 views
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
11. Re: [OT] Using DIR (CMD) with redirection to a file
- Posted by kinz Oct 05, 2009
- 2539 views
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
12. Re: [OT] Using DIR (CMD) with redirection to a file
- Posted by znorq2 Oct 06, 2009
- 2470 views
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 - "/"?
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;
- Created folder "æøåÆØÅ" under "c:\data\test".
- Opened console (cmd)
- Changed to "c:\data\test"
- Confirmed current code page 850 (using chcp w/o params.)
- chcp 865
- dir *.* /b > files.txt
- Opened "files.txt" using notepad.
- 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);
- Created date/time
- Created by
- Filename/path
Kenneth / ZNorQ
13. Re: [OT] Using DIR (CMD) with redirection to a file
- Posted by kinz Oct 06, 2009
- 2488 views
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.
This is what I did;
- Created folder "æøåÆØÅ" under "c:\data\test".
- Opened console (cmd)
- Changed to "c:\data\test"
- Confirmed current code page 850 (using chcp w/o params.)
- chcp 865
Try the chcp w/o params to see if cp was changed to 865 really.
- dir *.* /b > files.txt
- Opened "files.txt" using notepad.
- Changed to font to "Terminal".
OK, Terminal has strongly OEM encoding.
Letters "æøåÆØÅ" are now visible.
So, DIR worked in OEM (850).
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.
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);
- Created date/time
- Created by
- 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
14. Re: [OT] Using DIR (CMD) with redirection to a file
- Posted by krg Oct 13, 2009
- 2287 views
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.
15. Re: [OT] Using DIR (CMD) with redirection to a file
- Posted by znorq2 Oct 15, 2009
- 2263 views
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