Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to output IP address to file with powershell "Write-Output" command without null values

I’m trying to write an IP address (It’s just a random test IP I used) to a file using powershell’s Write-Output and it’s writing the IP address to the file but adding null values after every character. Is there any way to do this properly, without the null characters?

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I’m not sure why, but Write-Output '10.0.0.24' >> aws_hosts seem to produce an UTF-16 file (with at least 2 bytes per character) and then your VS Code tries to interpret it as UTF-8 showing all those \0 paddings as characters of its own.

Try '10.0.0.24' | Out-File -Encoding UTF8 -Append aws_hosts instead. That allows to control the output encoding.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading