Home > Mobile >  How to output IP address to file with powershell "Write-Output" command without null value
How to output IP address to file with powershell "Write-Output" command without null value

Time:05-03

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

CodePudding user response:

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.

  • Related