<dependency><groupId>io.cloudsoft.windows</groupId><artifactId>winrm4j</artifactId><version>0.12.3</version></dependency>
- 在执行的命令中含有特殊字符
命令中含有 中括号 [] 在使用powershell 执行命令时,中括号表示强制转换运算符,就需要转义处理。文件名称是 [P]test.xml 包含有中括号,在单个中括号前面使用 ``转义处理,在将整个文件路径放在单引号中。有的特殊字符使用cmd 可以正常执行,使用powershell执行时需要特殊处理。
powershell type 'D:\\``[P``]test.xml'
- 在使用type 或 get-content 命令获取文件内容时,文件内容乱码。
即使加上了 -Encoding UTF8 也乱码。
powershell type 'D:\\``[P``]test.xml' -Encoding UTF8
此时需要设置命令窗口的编码格式,在执行命令之前 先执行 chcp 65001
chcp 65001 | powershell type 'D:\\``[P``]test.xml'