在 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 命令之后

uj5u.com熱心網友回復:
我認為問題源于chcp 65001生效,即 UTF-8 代碼頁。
在代碼頁65001生效的情況下- powershell.exeWindows 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 終端中運行您的批處理檔案,該終端可在 Microsoft Store中獲得,而不是在舊的控制臺視窗中。
您可以暫時切換到其他
65001代碼頁,假設它仍然支持您需要的所有字符;應用于上面的例子:chcp 437 & powershell -noprofile -c "'hi'" & chcp 65001您可以從 Windows PowerShell 切換到PowerShell (Core) 7 ,即按需安裝的跨平臺后續版本。它的CLI不再
pwsh.exe出現問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/415813.html
標籤:
