输出中每个其他字符之间的NUL字节 [英] NUL-byte between every other character in output
问题描述
我正在使用Ruby读取文件,然后将文件打印到stdout,将输出重定向到Windows PowerShell中的文件。
但是,当我检查文件我得到这个输入:
PS D:> head -n 1 .\inputfile
< text id =http://observer.guardian.co.uk/osm/story/0,,1009777,00.html> < S取代;流氓NNS流氓
,,肆意JJ无节制的激情NN激情
- : - 和CC和没有DT没有执行JJ执行
e盒NNS框。 SENT < / S取代;
...此输出:
PS $ D:> head -n 1 .\outputfile
ÿ_< t e x t i d =h t t p:/ / o b s e r v e r。g u a r d i a n。c o。u k / o s m / s t o r y / 0,,1 0 0 9 7 7 7,0
0。h t m l < s> H o o l i g a n s N N S H o o l i g a n,,
,u n b r i d l e d J J u n b r i d l e d p a s s i n n N p a s s i o n
- : - a n d C C a n d n o D T n e e e e e e u u i i e e J e b N e S e o S E N T。 < / s>
如何发生?
编辑:由于我的问题与Ruby没有任何关系,我已经删除了Ruby代码,并包含了我对Windows shell的使用。
在PowerShell中>
与 | Out-File
和Out-File默认为Unicode编码。尝试这样做,而不是使用>
:
... | Out-File输出文件 - 编码ASCII
I'm using Ruby to read and then print a file to stdout, redirecting the output to a file in Windows PowerShell.
However, when I inspect the files, I get this for the input:
PS D:> head -n 1 .\inputfile
<text id="http://observer.guardian.co.uk/osm/story/0,,1009777,00.html"> <s> Hooligans NNS hooligan
, , , unbridled JJ unbridled passion NN passion
- : - and CC and no DT no executive JJ executiv
e boxes NNS box . SENT . </s>
... yet this for the output:
PS D:> head -n 1 .\outputfile
ÿ_< t e x t i d = " h t t p : / / o b s e r v e r . g u a r d i a n . c o . u k / o s m / s t o r y / 0 , , 1 0 0 9 7 7 7 , 0
0 . h t m l " > < s > H o o l i g a n s N N S h o o l i g a n , ,
, u n b r i d l e d J J u n b r i d l e d p a s s i o n N N p a s s i o n
- : - a n d C C a n d n o D T n o e x e c u t i v e J J
e x e c u t i v e b o x e s N N S b o x . S E N T . < / s >
How can this happen?
Edit: since my problem didn't have anything to do with Ruby, I've removed the Ruby-code, and included my usage of the Windows shell.
In PowerShell >
is effectively the same as | Out-File
and Out-File defaults to Unicode encoding. Try this instead of using >
:
... | Out-File outputfile -encoding ASCII
这篇关于输出中每个其他字符之间的NUL字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!