[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[问题求助] [已解决]以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 ...测试'
复制代码
最后发现是自己编辑器的问题

返回列表