Reputation: 3883
I'm writing a program that outputs a sequence of hex digits like does xxd -ps
command.
This output is intended to be converted into a binary file, e.g. with xxd -ps -r
.
When I try to invoke xxd -ps -r
on my hex output in PowerShell I don't get the desired binary, xxd's output is empty.
After some investigation I've revealed that PowerShell's Write-Output, it's alias echo and output redirection '>' — all they insert excessive characters like '\00' and some others into output.
How to get rid of this behavior and wean Powershell from corrupting data flows between commands?
I would like Powershell to behave like the good old cmd:
ps>java -cp HelloWorld > hello.txt
ps>xxd -ps hello.txt > hello.hex
ps>xxd -ps -r hello.hex
ps>HelloWorld
ps>
Currently the last command has empty output.
Now I will write my own hex to binary converter in java, which is ok for my project, even better, but I think I will eventually stumble upon this problem in the future so I want to be prepared.
Upvotes: 5
Views: 2041
Reputation: 24826
I've found something similar in the past. If the data is binary, redirection produces a corrupted output due to newline characters. I've resolved thanks to this good article.
Upvotes: 3