图形 CLI 在 运行 批处理文件中的 powershell 命令后更改
Graphic CLI changed after run the powershell command in batch file
在 PowerShell 代码之后,批处理文件 CLI 有点不同,我想改回来
可以看到字体变了,颜色也变了一点
在 PowerShell 命令之前
PowerShell 命令后
@echo off
echo +==================================================+
echo ^|**********************Login***********************^|
echo +==================================================+
echo.
echo Login
setlocal DisableDelayedExpansion
set /p input=Username:
::powershell command
set "psCommand=powershell -Command "$pword = read-host 'Enter password' -AsSecureString ; ^
$BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword); ^
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)""
for /f "usebackq delims=" %%p in (`%psCommand%`) do set passwords=%%p
)
if %passwords% == 123 goto sucess
exit
END LOCAL
:sucess
cls
echo welcom back %Username%!
echo :)
pause
exit
我看到了不同
在 Powershell 命令之前
在 Powershell 命令之后
我认为问题源于 chcp 65001
生效,即 UTF-8 代码页。
随着代码页 65001
生效,powershell.exe
- Windows PowerShell 的 CLI - 确实不幸地展示了您描述的症状:当前选择的字体更改为旧版 光栅字体,字形(字符)支持有限。
以下命令演示了问题(运行 来自 cmd.exe
):
:: Unexpectedly switches to a raster font.
:: Note: No longer occurs in PowerShell (Core) 7+, with pwsh.exe
chcp 65001 & powershell -noprofile -c "'hi'"
您有以下选项:
运行 您的批处理文件在 Windows Terminal, available in the Microsoft Store 而不是旧控制台 window.
您可以暂时切换到代码页其他而不是65001
,假设它仍然支持你需要的所有字符;应用于上面的例子:
chcp 437 & powershell -noprofile -c "'hi'" & chcp 65001
您可以从 Windows PowerShell 切换到 PowerShell (Core) 7+, the install-on-demand, cross-platform successor edition. Its CLI、pwsh.exe
,问题不再出现。
在 PowerShell 代码之后,批处理文件 CLI 有点不同,我想改回来
可以看到字体变了,颜色也变了一点
在 PowerShell 命令之前
PowerShell 命令后
@echo off
echo +==================================================+
echo ^|**********************Login***********************^|
echo +==================================================+
echo.
echo Login
setlocal DisableDelayedExpansion
set /p input=Username:
::powershell command
set "psCommand=powershell -Command "$pword = read-host 'Enter password' -AsSecureString ; ^
$BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword); ^
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)""
for /f "usebackq delims=" %%p in (`%psCommand%`) do set passwords=%%p
)
if %passwords% == 123 goto sucess
exit
END LOCAL
:sucess
cls
echo welcom back %Username%!
echo :)
pause
exit
我看到了不同
在 Powershell 命令之前
在 Powershell 命令之后
我认为问题源于 chcp 65001
生效,即 UTF-8 代码页。
随着代码页 65001
生效,powershell.exe
- Windows PowerShell 的 CLI - 确实不幸地展示了您描述的症状:当前选择的字体更改为旧版 光栅字体,字形(字符)支持有限。
以下命令演示了问题(运行 来自 cmd.exe
):
:: Unexpectedly switches to a raster font.
:: Note: No longer occurs in PowerShell (Core) 7+, with pwsh.exe
chcp 65001 & powershell -noprofile -c "'hi'"
您有以下选项:
运行 您的批处理文件在 Windows Terminal, available in the Microsoft Store 而不是旧控制台 window.
您可以暂时切换到代码页其他而不是
65001
,假设它仍然支持你需要的所有字符;应用于上面的例子:chcp 437 & powershell -noprofile -c "'hi'" & chcp 65001
您可以从 Windows PowerShell 切换到 PowerShell (Core) 7+, the install-on-demand, cross-platform successor edition. Its CLI、
pwsh.exe
,问题不再出现。