Board logo

标题: [问题求助] PowerShell怎样把字符串gb2312转换成utf-8 [打印本页]

作者: newswan    时间: 2021-4-25 18:42     标题: PowerShell怎样把字符串gb2312转换成utf-8

命令输出到文件 是 gb2312,
但是,要把命令输出添加到utf-8编码的文件中。直接输出的话,中文是乱码
怎么用 powershell 转成 utf-8 ,再输出到文件中
作者: Batcher    时间: 2021-4-25 21:55

回复 1# newswan
  1. Get-Content 1.txt | Out-File 2.txt -Encoding UTF8
复制代码

作者: newswan    时间: 2021-4-26 00:42

回复 2# Batcher


    "添加"到已经存在的 utf-8 文件中,outfile 会覆盖文件,能不能直接转换,避免临时文件
把 powershell 代码夹在bat 中,又怎么做?

这种流程,echo "啊" | powershell "" >>1.txt
作者: wxyz0001    时间: 2021-4-26 01:18

本帖最后由 wxyz0001 于 2021-4-26 01:19 编辑

回复 3# newswan
试试用Add-Content
  1. Get-Content 1.txt | Add-Content 1.txt -Encoding UTF8
复制代码

作者: newswan    时间: 2021-4-26 01:39

回复 4# wxyz0001


    谢谢,在批处理中,怎么把命令的输出 传给 powershell 命令行? 只能使用 变量?

我是想达到相同的功能,用powershell 替换 iconv
  1. echo "something" | iconv -f CP936 -t utf-8  >>1.txt
复制代码

作者: Batcher    时间: 2021-4-26 08:34

回复 3# newswan
  1. Get-Content 1.txt | Out-File 2.txt -Encoding UTF8 -Append
复制代码

作者: xczxczxcz    时间: 2021-4-26 13:46

回复 5# newswan


    真的想学 POWERSHELL  先把电脑上的第三方命令行全删掉。这样才进步快。
  1. sc '.\1.txt' -value 'it is ok' -enc utf8 -force
复制代码

作者: newswan    时间: 2021-4-26 23:20

回复 7# xczxczxcz


    powershell 有些太庞大了,要花很多时间啊
作者: Batcher    时间: 2021-4-27 00:00

回复 8# newswan


    学好PowerShell有可能在面试过程中多要点薪水




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2