Board logo

标题: [问题求助] [已解决]以bat为载体运行powershell脚本,但是为何不支持中文,请看码 [打印本页]

作者: cenbaolin    时间: 2019-6-4 22:08     标题: [已解决]以bat为载体运行powershell脚本,但是为何不支持中文,请看码

将下面的代码保存为
  1. test.bat
复制代码
,执行后发现前3个字符均被截掉了,请大佬指教
  1. <# : Begin batch (batch script is in commentary of powershell v2.0+)
  2. @echo OFF
  3. chcp 65001
  4. : Use local variables
  5. setlocal
  6. : Change current directory to script location - useful for including .ps1 files
  7. cd %~dp0
  8. : Invoke this file as powershell expression
  9. powershell -executionpolicy remotesigned -Command "Invoke-Command -ScriptBlock ([scriptblock]::Create($([System.IO.File]::ReadAllText('%~f0')))) -ArgumentList ([string]'%*').split()"
  10. : Restore environment variables present before setlocal and restore current directory
  11. endlocal
  12. : End batch - go to end of file
  13. goto:eof
  14. #>
  15. # here start your powershell script
  16. # example: include another .ps1 scripts (commented, for quick copy-paste and test run)
  17. #. ".\anotherScript.ps1"
  18. # example: standard input from console
  19. Write-Host  'Running ...测试'
复制代码
最后发现是自己编辑器的问题




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