hidden hit counter
Help!

How to pipe unicode output to non-unicode input?

 
Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> General Discussion RSS
Next:  Pausing Start/Run result window?  
Author Message
Evgeny Zoldin
External


Since: Apr 26, 2007
Posts: 2



PostPosted: Thu Apr 26, 2007 2:30 pm    Post subject: How to pipe unicode output to non-unicode input?
Archived from groups: microsoft>public>windowsxp>general (more info?)


Good day.

I call in command window (cmd.exe) a command that produces unicode output,
e.g. subinacl.exe from Resource Kit Tools and I want to find in the output
some string. For instance, in order to define who is the owner of
C:\temp.txt I call subinacl.exe and pipe the output to find.exe:

C:\>subinacl.exe /nostatistic /file C:\temp.txt /display=owner | find.exe
"/owner"

but such command returns nothing because the out of subinacl.exe delivered
in Unicode mode, while in the part

find.exe "/owner"

the string "/owner" is interpreted as ANSI, but not Unicode.

The initial call of cmd.exe with option "/A" doesn't help (probably because
it only affects internal commands of WinXp)

How to resolve the problem?
Is there a way to convert on-fly unicode output into ANSI ?

Thank you
Evgeny Zoldin
Back to top
"Pegasus
External


Since: Oct 14, 2005
Posts: 4688



PostPosted: Fri Apr 27, 2007 12:04 am    Post subject: Re: How to pipe unicode output to non-unicode input? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Evgeny Zoldin" wrote in message

> Good day.
>
> I call in command window (cmd.exe) a command that produces unicode
output,
> e.g. subinacl.exe from Resource Kit Tools and I want to find in the output
> some string. For instance, in order to define who is the owner of
> C:\temp.txt I call subinacl.exe and pipe the output to find.exe:
>
> C:\>subinacl.exe /nostatistic /file C:\temp.txt /display=owner | find.exe
> "/owner"
>
> but such command returns nothing because the out of subinacl.exe delivered
> in Unicode mode, while in the part
>
> find.exe "/owner"
>
> the string "/owner" is interpreted as ANSI, but not Unicode.
>
> The initial call of cmd.exe with option "/A" doesn't help (probably
because
> it only affects internal commands of WinXp)
>
> How to resolve the problem?
> Is there a way to convert on-fly unicode output into ANSI ?
>
> Thank you
> Evgeny Zoldin
>
>

You could do this:

@echo off
subinacl.exe /nostatistic /file C:\temp.txt /display=owner > c:\temp.uni
type c:\temp.uni | find.exe "/owner"

for /F "tokens=*" %* in ('subinacl.exe /nostatistic /file C:\temp.txt
/display=owner ^| find.exe "/owner"') do echo %*
Back to top
Evgeny Zoldin
External


Since: Apr 26, 2007
Posts: 2



PostPosted: Fri Apr 27, 2007 12:04 am    Post subject: Re: How to pipe unicode output to non-unicode input? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Dear Pegasus,

I already tried both your variants and they both don't work by the same
reason:
> @echo off
> subinacl.exe /nostatistic /file C:\temp.txt /display=owner > c:\temp.uni
> // <- here c:\temp.uni has UNICODE text
> type c:\temp.uni | find.exe "/owner"
> // <- here "/owner" is NOT UNICODE
therefore non-unicode "/owner" can not be found in unicode file. If you just
call

type c:\temp.uni

you will get something like:

+ F i l e C : \ t e m p . t x t
/ o w n e r = n .....

but not

+File C:\temp.txt
/owner =n.....

Just the same problem in
> for /F "tokens=*" %* in ('subinacl.exe /nostatistic /file C:\temp.txt
> /display=owner ^| find.exe "/owner"') do echo %*

Regards
Evgeny Zoldin
Back to top
"Pegasus
External


Since: Oct 14, 2005
Posts: 4688



PostPosted: Fri Apr 27, 2007 12:44 am    Post subject: Re: How to pipe unicode output to non-unicode input? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Evgeny Zoldin" wrote in message

> Dear Pegasus,
>
> I already tried both your variants and they both don't work by the same
> reason:
> > @echo off
> > subinacl.exe /nostatistic /file C:\temp.txt /display=owner > c:\temp.uni
> > // <- here c:\temp.uni has UNICODE text
> > type c:\temp.uni | find.exe "/owner"
> > // <- here "/owner" is NOT UNICODE
> therefore non-unicode "/owner" can not be found in unicode file. If you
just
> call
>
> type c:\temp.uni
>
> you will get something like:
>
> + F i l e C : \ t e m p . t x t
> / o w n e r = n .....
>
> but not
>
> +File C:\temp.txt
> /owner =n.....
>
> Just the same problem in
> > for /F "tokens=*" %* in ('subinacl.exe /nostatistic /file C:\temp.txt
> > /display=owner ^| find.exe "/owner"') do echo %*
>
> Regards
> Evgeny Zoldin
>
>

Your report is at variance with my test. I took this unicode file:

000000 FF FE 42 00 61 00 63 00 6B 00 75 00 70 00 20 00 ?B a c k u p
000010 53 00 74 00 61 00 74 00 75 00 73 00 0D 00 0A 00 S t a t u s ? ?
000020 4F 00 70 00 65 00 72 00 61 00 74 00 69 00 6F 00 O p e r a t i o
000030 6E 00 3A 00 20 00 42 00 61 00 63 00 6B 00 75 00 n : B a c k u
000040 70 00 0D 00 0A 00 41 00 63 00 74 00 69 00 76 00 p ? ? A c t i v

and used this command:
type backup01.log > backup01.txt
to generate this file:

000000 42 61 63 6B 75 70 20 53 74 61 74 75 73 0D 0A 4F Backup Status??O
000010 70 65 72 61 74 69 6F 6E 3A 20 42 61 63 6B 75 70 peration: Backup
000020 0D 0A 41 63 74 69 76 65 20 62 61 63 6B 75 70 20 ??Active backup
000030 64 65 73 74 69 6E 61 74 69 6F 6E 3A 20 46 69 6C destination: Fil
000040 65 0D 0A 4D 65 64 69 61 20 6E 61 6D 65 3A 20 22 e??Media name: "

The first file is obviously Unicode, the second pure ANSI. Furthermore,
the second file is only half the size of the first file.

I suggest you run a similar test with the output from subinacl.exe and
examine each file with a binary lister.
Back to top
Eric-01
External


Since: Nov 03, 2011
Posts: 1



PostPosted: Thu Nov 03, 2011 9:26 am    Post subject: Re: How to pipe unicode output to non-unicode input? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Download and install LibIconv for Windows from:
http://gnuwin32.sourceforge.net/packages/libiconv.htm
Don't forget to install de necessary DLL-files in de Windows-System32
folder:
2004.10.13 23:08 16.896 iconv.exe
2004.10.13 23:08 11.776 libcharset1.dll
2004.09.29 20:48 12.604 libiconv-man.pdf
2004.10.13 23:08 978.432 libiconv2.dll
2004.10.09 17:25 101.888 libintl3.dll

Then you can pipe the output with iconv.exe.

An example command in cmd.exe (tested in Windows XP):
subinacl.exe /nostatistic /noverbose /file test.txt /display |iconv.exe
-f UCS-2LE -t CP850 |find.exe "/owner"
Back to top
Display posts from previous:   
Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> General Discussion All times are: Eastern Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum