简体   繁体   English

在批处理文件中运行 powershell 命令后更改了图形 CLI

[英]Graphic CLI changed after run the powershell command in batch file

After the PowerShell code the batch file CLI is a little different, i want to change it back在 PowerShell 代码之后批处理文件 CLI 有点不同,我想把它改回来

You can see the font changed and the color changed a little可以看到字体变了,颜色也变了一点

Before PowerShell command PowerShell 命令之前

在此处输入图像描述

After PowerShell command 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

I see the different我看到了不一样的

before Powershell command Powershell 命令之前

在此处输入图像描述

after the Powershell command在 Powershell 命令之后

在此处输入图像描述

I presume the problem stems from chcp 65001 being in effect, ie the UTF-8 code page.我认为问题源于chcp 65001生效,即 UTF-8 代码页。

With code page 65001 in effect, powershell.exe - the CLI of Windows PowerShell - indeed unfortunately exhibits the symptom you describe: the currently selected font is changed to a legacy raster font with limited glyph (character) support.在代码页65001生效的情况下, powershell.exe - Windows PowerShellCLI - 确实表现出您描述的旧支持症状。

The following command demonstrates the problem (run from cmd.exe ):以下命令演示了该问题(从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'"

You have the following options :您有以下选择

  • Run your batch file in Windows Terminal , available in the Microsoft Store instead of in a legacy console window.Windows 终端中运行您的批处理文件,该终端可在 Microsoft Store中获得,而不是在旧版控制台 window 中。

  • You can temporarily switch to a code page other than 65001 , assuming it still supports all the characters you need ;您可以暂时切换到65001以外的代码页,假设它仍然支持您需要的所有字符 applied to the example above:应用于上面的例子:

     chcp 437 & powershell -noprofile -c "'hi'" & chcp 65001
  • You can switch from Windows PowerShell to PowerShell (Core) 7+ , the install-on-demand, cross-platform successor edition.您可以从 Windows PowerShell 切换到PowerShell (Core) 7+ ,即按需安装、跨平台的后续版本。 Its CLI , pwsh.exe , no longer exhibits the problem.它的CLIpwsh.exe ,不再出现问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM