找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 15699|回复: 0

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

[复制链接]
发表于 2019-6-4 22:08:40 | 显示全部楼层 |阅读模式
将下面的代码保存为
  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 ...测试'
复制代码
最后发现是自己编辑器的问题
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-17 01:44 , Processed in 0.024686 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表