TechTalkz.com Logo Ask the Experts!

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Microsoft > Microsoft Windows Powershell

Bug in out-file or >

Microsoft Windows Powershell

 
 
 
Thread Tools Display Modes
Old 04-02-2008, 04:24 PM   #1
chucky314
Guest
 
Posts: n/a
Bug in out-file or >

I noticed this when I was trying to convert a script from vbs to powershell...

From the normal command line:
echo Test >> temp.txt

This file (in hex)looks like:
54 65 73 74 20 0D 0A

Now, in powershell:
write-output "test" >> output.txt

This is what the file looks like in hex:
FF FE 54 00 65 00 73 00 74 00 0D 00 0A 00

The FF FE at the beginning is killing an import process that is checking per
byte of a file.

If out-file is used with the -encoding "ASCII" option, it appears fine
(write-output "Test" | out-file -encoding ASCII -filepath output2.txt)

It appears to me that powershell uses ">" and ">>" different than the
default command line... is this correct?

 
Old 04-02-2008, 05:20 PM   #2
Jon
Guest
 
Posts: n/a
Re: Bug in out-file or >

Well yeah the default is unicode output, rather than the ascii with cmd.exe,
which is what you are observing. You could perhaps modify your 'import
process' to skip the first 2 bytes, or just use the -encoding switch, as
you've discovered.

I think those first 2 bytes indicate that the rest of the file is in unicode
format. You get the same if you create a file in notepad and save it in
unicode format.

FF FE - Unicode format
FE FF - Unicode (big endian)
etc

--
Jon


"chucky314" <chucky314@discussions.microsoft.com> wrote in message
news:F7F9D648-90A2-42DE-B62B-3BCDF4819039@microsoft.com...
>I noticed this when I was trying to convert a script from vbs to
>powershell...
>
> From the normal command line:
> echo Test >> temp.txt
>
> This file (in hex)looks like:
> 54 65 73 74 20 0D 0A
>
> Now, in powershell:
> write-output "test" >> output.txt
>
> This is what the file looks like in hex:
> FF FE 54 00 65 00 73 00 74 00 0D 00 0A 00
>
> The FF FE at the beginning is killing an import process that is checking
> per
> byte of a file.
>
> If out-file is used with the -encoding "ASCII" option, it appears fine
> (write-output "Test" | out-file -encoding ASCII -filepath output2.txt)
>
> It appears to me that powershell uses ">" and ">>" different than the
> default command line... is this correct?
>


 
Old 04-02-2008, 05:20 PM   #3
Jon
Guest
 
Posts: n/a
Re: Bug in out-file or >


Looks like the 'FF FE' indicates that it's 'little endian'

cf

Globalize your On Demand Business
http://www-306.ibm.com/software/glob...de/formats.jsp


from the page ......


"Determining Endianness

Unicode provides a method by which programmers can "tag" UTF-16 or UTF-32
data files to specifically designate whether the data in it is big or little
endianness. This is done by placing a special character, called the byte
order mark (BOM) at the beginning of the data. The Unicode value for the
byte order mark is 0xFEFF. Similarly, Unicode also guarantees that the
"byte-swapped" version of this character (i.e. 0xFFFE) is NOT a valid
character. So if you are reading a file encoded as UTF-16, but don't know
anything about the endianness of the data, a BOM of FE FF as the first 2
bytes would denote "big endian" data, while a BOM of FF FE would denote
"little endian" data to follow. Similarly, in UTF-32, a BOM of 00 00 FE FF
would designate big endianess, while a BOM of FF FE 00 00 would designate
little endianness."


--
Jon

 
Old 04-02-2008, 06:21 PM   #4
Karl Prosser[MVP]
Guest
 
Posts: n/a
Re: Bug in out-file or >

In powershell > and >> are "effectively" syntactical "aliases" for
out-file , and thus they work with the default Unicode settings. If you
have to explicitly declare ASCII encoding then you'll have to explicitly
pipe it to out-file..

chucky314 wrote:
> I noticed this when I was trying to convert a script from vbs to powershell...
>
> From the normal command line:
> echo Test >> temp.txt
>
> This file (in hex)looks like:
> 54 65 73 74 20 0D 0A
>
> Now, in powershell:
> write-output "test" >> output.txt
>
> This is what the file looks like in hex:
> FF FE 54 00 65 00 73 00 74 00 0D 00 0A 00
>
> The FF FE at the beginning is killing an import process that is checking per
> byte of a file.
>
> If out-file is used with the -encoding "ASCII" option, it appears fine
> (write-output "Test" | out-file -encoding ASCII -filepath output2.txt)
>
> It appears to me that powershell uses ">" and ">>" different than the
> default command line... is this correct?
>

 
 

Thread Tools
Display Modes



< Home - Windows Help - MS Office Help - Hardware Support >


New To Site? Need Help?

All times are GMT. The time now is 01:08 AM.


vBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2013, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional