How to pipe unicode output to non-unicode input?

E

Evgeny Zoldin

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
 
P

Pegasus \(MVP\)

Evgeny Zoldin said:
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 %*
 
E

Evgeny Zoldin

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
 
P

Pegasus \(MVP\)

Evgeny Zoldin said:
Dear Pegasus,

I already tried both your variants and they both don't work by the same
reason:
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

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top