![Board logo](images/default/logo.gif)
标题: [问题求助] [已解决]以bat为载体运行powershell脚本,但是为何不支持中文,请看码 [打印本页]
作者: cenbaolin 时间: 2019-6-4 22:08 标题: [已解决]以bat为载体运行powershell脚本,但是为何不支持中文,请看码
将下面的代码保存为复制代码
,执行后发现前3个字符均被截掉了,请大佬指教- <# : Begin batch (batch script is in commentary of powershell v2.0+)
- @echo OFF
- chcp 65001
- : Use local variables
- setlocal
- : Change current directory to script location - useful for including .ps1 files
- cd %~dp0
- : Invoke this file as powershell expression
- powershell -executionpolicy remotesigned -Command "Invoke-Command -ScriptBlock ([scriptblock]::Create($([System.IO.File]::ReadAllText('%~f0')))) -ArgumentList ([string]'%*').split()"
- : Restore environment variables present before setlocal and restore current directory
- endlocal
- : End batch - go to end of file
- goto:eof
-
- #>
- # here start your powershell script
-
- # example: include another .ps1 scripts (commented, for quick copy-paste and test run)
- #. ".\anotherScript.ps1"
-
- # example: standard input from console
-
- Write-Host 'Running ...测试'
复制代码
最后发现是自己编辑器的问题![](images/smilies/grapeman/15.gif)
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |