如何批量覆盖特定行的文本

如何批量覆盖特定行的文本

我已经尝试过这个:{@echo off setlocal enableextensions enabledelayedexpansion

    for /f %%a in ('copy /Z "%~dpf0" nul') do set "CR=%%a"

    <nul set /p"=This is the line 1 !CR!"
    <nul set /p"=This is the line 2 "

但是当我用自己的代码尝试时,出现了这个奇怪的故障。

毛刺

我试图获得这样的结果:

看起来像

左上角和右上角应该代表我想要的样子,但左下角和右下角显示的却是我不想要的样子。我太笨了,不明白发生了什么,也不知道该如何修复。(如果您想知道,是的,这是我想为我自己的基于命令提示符/终端的终端/CLI 项目做的事情

任何帮助,将不胜感激。

如果您想查看的话,这是代码。

对于变量,我想要实现的更像是一种“对齐效果”,这样,如果我在另一台计算机上运行这个程序,CPU 字符串就不会将一些文本推到右边

@echo off

::: Important code, do not touch!
chcp 65001 >nul
for /f "tokens=2 delims==" %%E in ('wmic path Win32_Battery get EstimatedChargeRemaining /value') do (set "Battery=%%E")
for /f "tokens=2 delims==" %%E in ('wmic path Win32_Processor get Name /value') do (set "CPUName=%%E")
for /f "tokens=2 delims==" %%E in ('wmic path Win32_VideoController get CurrentVerticalResolution /value') do (set "verti=%%E")
for /f "tokens=2 delims==" %%E in ('wmic path Win32_VideoController get CurrentHorizontalResolution /value') do (set "horiz=%%E")
for /f "tokens=2 delims==" %%E in ('wmic path Win32_PhysicalMemory get Capacity /value') do (set "memory=%%E")
for /f "tokens=2 delims==" %%E in ('wmic path Win32_DiskDrive get Size /value') do (set "diskcap=%%E")

set /a kbmem=%memory:~0,-4%
set /a mbmem = kbmem/1024
set /a memory = mbmem/1024
set /a kb=%diskcap:~0,-4%
set /a mb = kb/1024
set /a gb = mb/1024
set /a gb = gb+6


:::  <nul set /p"=This is the line 1 !CR!"
::: [38;2;37;88;62m
setlocal enableextensions enabledelayedexpansion


<nul set /p"=┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐"
<nul set /p"=│                                                                                                    ~───~.                  ,,.~────~..,                   │"
<nul set /p"=│    Monstera Terminal 1.01 UEFI                                                                   ,`  ,     "^~.       ,─'     ,,,,,      `^~.             │"
<nul set /p"=│    ───────────────────────────                                                                      ██▒╢▓@╦▄,   ─   ,"  ,▄▄█████████▓▓▓@▄▄   `─           │"
<nul set /p"=│                                                                                             ─`   ▄▓████▌▒╫▓▓██▄   ┐░  ,███▓▓▓▓▓▓▓▓▓▓▓███████▄   \         │"
<nul set /p"=│    Dashboard                                                                             .─   ╓▓▓▓▓▓▓▓███▓▒▓████Ç    ╒██▓▓▓██▓▓██▓▓▓▓╢╢╢╢▒▒▀▀█▄  ",       │"
<nul set /p"=│    ─────────────────────────────────────────────                                       /   ╓╫╣╢╢╢╢▓▓▓▓▓▓██▓▒▓███    ██╣▓██▓▓█▓▓▓▓╣╣╣╣╣╣╢╣╣╢╣▒▒%   ░       │"
<nul set /p"=│                                                                                       ░  ,▒╢╢╢╫╣▓▓▓▓▓▓▓▓▓▓▓██▓▓█▌   ▓▓▓█▓▓▓▓▓▓▓╣╣╢╣╣╢▒▒▒▒▒▒▒▒▒╖"⌐  ░      │"
<nul set /p"=│    User: Maxzie Planteronix                                                           ,`  ▄▓▓╣╣╫╣▓▒╢╣╢▓▓▓▓▓▓█████▓  ]▓▓▓▓▓▓╢╣╢╢╣╣╣╢╢╢╢╢╢╢╣╢▓╣@╢╣▒▒┐  \    │"
<nul set /p"=│    Date: 10/3/2023 at 6:40 PM                                                        /   █▓▓▓▓▓▀`      ╙╙▓▓▓▓▓███▌@@▓╢╣╣▒▒▒▒▒▒▒▒╣▒╢▒ÑÑÑÑ╩╨╜╙▀▀▓▓▓▓▓Ç  ░   │"
<nul set /p"=│    Updates: Please wait for the owner to update the system.                        ░   g▓█▀▀╙   ,,╓⌂⌂,µ,,,▄▄▓▓▓▓██╣▒█▓▓▓▓▓▓▓▓▓╣@p▄,                  ,`   │"
<nul set /p"=│                                                                                    ░  ╙╙  ,╥H╬▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▀▀╣████▓▓▓▓▓▓▓▓▓▓▓███████▄▄▄▄▄▄▄g,   ",   │"
<nul set /p"=│    CPU: %CPUName%                                    ─  ╓▒▒▒▒▒▒▒╣▓▓▓▓▓▓▓███████████╫██▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓██▓▓██████████▌µ  \  │"
<nul set /p"=│    Resolution: %horiz%x%verti%                                                              g╢▒▒▒╢╫▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓╢▓▀█▓▓▓▓▓▓▌╙╙▀▓▓▓▓▓▓▓▓▓▓▓▀██▓▓▓▓███▄  ░ │"
<nul set /p"=│    Memory: 8GB (1 out of 4 slots are used.)                                        ⌐  ▓▓╣▒▓▓▓▓▓▓▓▓▓▓█▀▀▀╙  ,▐▓▓▓▓▓▓███▓▀▓▓▓▓▓▓▓▓▄g ╙▀▀▓▓▓╣╣╣╢╢╢▓▓▓▓███  ░ │"
<nul set /p"=│    Storage: 12.5GB of 128GB                                                        ⌐  ▓▓▓▓╣▓▓▓▓██▀▀`   ╓@╬╣╢▓▓▓██▓▒███████▓▓▓▓▓╢╢▓▓▓▄▄,   ╙╙╝▒▒▒▒▒▒▓▓▓  ] │"
<nul set /p"=│    Graphics:                                                                       ▒  ▓▓▓▓▓██▀▀    ,╥@╣╢▓▓▓████▓██████████▓▓▓▓▓▓▓▄▄▒▒╢▓▓▓▓▄,   ╙Ñ╖ ╙╫▓  ] │"
<nul set /p"=│    Manufacturer: Amiercan Metagrands Inc.                                          ░  ▓▓▓██▀    ,φ▓╣╫▓▓▓████▓▓▓▓▓███▓▓▓████▀╙▀▀█▓▓▓▓█▓▓▓╢▓▓▓█▄    ╚, ▒  ░ │"
<nul set /p"=│                                                                                    ░  ▓▓█"    ,▒▒╢╫▓▓▓███▓▓▓▀▀╙╩▓▓█▓▓▓▓▓▓▓██▄    ▀▓▓▓▓▓▓▓▓▓▓▓▓█▌µ   \r  ░ │"
<nul set /p"=│    ─────────────────────────────────────────────                                   ▒  ▓▀     ╥▒▒╫▓▓▓▓▓▓▓▓▓▀    ▄▓██▓▓▓▓▓▓▓▓▓██▄    ╙▀▓▓▓▓▓██▓▓▓▓██▄    ,  │"
<nul set /p"=│                                                                                    ░  `    ╓▒▒▒▒▓▓▓▓▓▓▓▓▀    ,▓▓██▓▓▓▓▓▓▓▓▓▓▓▓██▄    ╙▓▓▓▓▓▓▓███▓▓██▄  \  │"
<nul set /p"=│                                                                                     ───  ,╣▒▒▒▒▓▓▓▓▓▓▓▀¬   ,▄▓▓█▓▓█▓▓▓▓▓▓▓██▓▓▓▓██▄    ╙▓▓╣▓▓▓▓██▓▓▓▓U j  │"
<nul set /p"=│                                                                                       ░  ╠╣▒▒╫▓▓▓▓▓█▀╘    ▄█▓▓▓▓▓▓█▓▌▓▓▓▓▓▓▓▓███▓▓██▌,   ▀╣▒╢╢╣▓▓▓▓▓▓  ┌  │"
<nul set /p"=│                                                                                        ,  ▐▒▒▓╢▓▓▓█'    ,▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌   ▀▓▓▓██▓▓███µ  "╣▒▒▒╢╣╢╢▓╩  ░  │"
<nul set /p"=│                                                                                            ▓╣╢▓▓▓▌     ╔█▓▓▓╣▒╢▓▓▓▓▓▓▓▓▓▓     ╙▓▓▓██▓▓██▌   ╙⌐"╙▒▒▒╜  /   │"
<nul set /p"=│                                                                                         ░  ╚▓╫▓▓█     á▓▓▓▓▒▒▓▀  ▓▓▌▓▓▓▓▓▌      ╟▓▓▓██▓███▄  "╖  ▒`  ░    │"
<nul set /p"=│                                                                                          \  ▐▓▓█     ╓▓▓▓╣▒▒▓`   ▓▓▌█▓▓▓▓█▌      ╙▒▓▓▓█▓▓██µ  "▒╜   ░     │"
<nul set /p"=│                                                                                           ,  ▀▓Ü    ┌▓▓▓╣╣╢▓    ▓▓▓▓█▓▓▓▓███▄     ╙▒╫▓▓▓▓▓██   "  ,`      │"
<nul set /p"=│                                                                                            \  ▐     ▓▓▓▒╣╢▓▌   ▐▓╣▓▓▓▓▓▓▓████▌     ║▒▓▓▓▓▓▓█  ¡──'`       │"
<nul set /p"=│                                                                                            ░  ┘    ╚▓▓╣╣╣╢▓   ▐▓▓╣╢▓▓█▓▓▓▓█████Ç    ▒╫▓▓▓▓▓╜  ░           │"
<nul set /p"=│                                                                                             "───`\   ╙╩▄▒╣▓  ╔▓▓▓▓▓▓▓█▓▓▓▓▓█████    ]▒▓▓▓╙  ,"            │"
<nul set /p"=│                                                                                                    '~   ╙▀▓▓╖╫▓▓▓▓▓█▓█▓▓▓▓▓▓████    ▓▓▓   ┌'              │"
<nul set /p"=│                                                                                                    '─.   ╙╩▓▓▓▓███▓╣▓▓▓▓▓▓█▀`    ▀   ─'                   │"
<nul set /p"=│                                                                                                        "~.   ▀▓███▒▒▓▓▓▀╙    ─└....─'                     │"
<nul set /p"=│                                                                                                          '^,  ▀██▒▒╜   .─``                               │"
<nul set /p"=│                                                                                                              \  ▀▀   .─                                   │"
<nul set /p"=│                                                                                                               ░....─'                                     │"
<nul set /p"=└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘"
pause >nul
cls
wow.cmd

答案1

@echo off && setlocal EnableDelayedExpansion 

set "_LF=<<con: <nul  & echo\"
%__AppDir__%chcp.com 65001 1>nul
set "_wmic=%__AppDir__%wbem\WMIC.exe"

for %%i in (
     Battery,Graphics,CPUName,DiskCap,Resolution,Lines,User,spc)do if "%%~i" == "spc" (
     set "_%%~i=" <nul & for /L %%L in (01 01 77)do set "_%%~i=!_%%~i! ")else set "%%~i=" <nul
     
for /f tokens^=2^delims^=:^  %%G in ('
     %__AppDir__%mode.com con: ^| %__AppDir__%findstr.exe ".*s:"')do if "!_lines!" == "" (
         set "_lines=%%~G")else if !_lines!%%~G neq 16084 %__AppDir__%mode.com con: cols=160 lines=84

for /f usebackq^tokens^=4delims^=^>^< %%i in (`
     !_wmic! path Win32_VideoController get CurrentVerticalResolution^,CurrentHorizontalResolution /format:xml ^|find "VALUE"
    `)do if Not Defined Resolution (set "Resolution=%%~i")else set "Resolution=!Resolution!x%%~i!_spc!"

for /f usebackq^tokens^=4delims^=^>^< %%i in (`
     !_wmic! path Win32_Battery get EstimatedChargeRemaining /format:xml ^|find "VALUE"`)do set "Battery=%%~i"
     
for /f usebackq^tokens^=4delims^=^>^< %%i in (`
     !_wmic! path Win32_VideoController get Name /format:xml ^|find "VALUE"`)do set "Graphics=%%~i!_spc!"

for /f usebackq^tokens^=4delims^=^>^< %%i in (`
     !_wmic! path Win32_PhysicalMemory get Capacity /format:xml ^|find "VALUE"`)do set "Memory=%%~i"
     
for /f usebackq^tokens^=4delims^=^>^< %%i in (`
     !_wmic! path Win32_Processor get Name /format:xml ^|find "VALUE"`)do set "CPUName=%%~i!_spc!"

for /f usebackq^tokens^=4delims^=^>^< %%i in (`
     !_wmic! path Win32_DiskDrive get Size /format:xml ^|find "VALUE"`)do set "DiskCap=%%~i"

for /f usebackq^tokens^=4delims^=^>^< %%i in (`
     !_wmic! OS Get LocalDateTime /format:xml ^|find "VALUE"`)do set "_dt=%%~i"

set "User=%UserName%!_spc!"
set "Date_Time=!_dt:~6,2!/!_dt:~4,2!/!_dt:~0,4! at !_dt:~8,2!:!_dt:~10,2!!_spc!"

for %%i in (kbmem,mbmem,mb,gb)do set "%%~i=" <nul
set /a "kbmem=%Memory:~0,-4%, kb=%DiskCap:~0,-4%"
set /a "mbmem=kbmem/1024, mb=kb/1024"
set /a "Memory=mbmem/1024, gb=mb/102"
set /a "gb=gb+6"

echo\ & <nul set /p "'=┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐" !_LF!
echo\ & <nul set /p "'=│                                                                                                    ~───~.                  ,,.~────~..,                   │" !_LF!
echo\ & <nul set /p "'=│    Monstera Terminal 1.01 UEFI                                                                   ,`  ,     "^^^^~.       ,─'     ,,,,,      `^^^^~.             │" !_LF!
echo\ & <nul set /p "'=│    ───────────────────────────                                                                      ██▒╢▓@╦▄,   ─   ,"  ,▄▄█████████▓▓▓@▄▄   `─           │" !_LF!
echo\ & <nul set /p "'=│                                                                                             ─`   ▄▓████▌▒╫▓▓██▄   ┐░  ,███▓▓▓▓▓▓▓▓▓▓▓███████▄   \         │" !_LF!
echo\ & <nul set /p "'=│    Dashboard                                                                             .─   ╓▓▓▓▓▓▓▓███▓▒▓████Ç    ╒██▓▓▓██▓▓██▓▓▓▓╢╢╢╢▒▒▀▀█▄  ",       │" !_LF!
echo\ & <nul set /p "'=│    ─────────────────────────────────────────────                                       /   ╓╫╣╢╢╢╢▓▓▓▓▓▓██▓▒▓███    ██╣▓██▓▓█▓▓▓▓╣╣╣╣╣╣╢╣╣╢╣▒▒%%   ░       │" !_LF!
echo\ & <nul set /p "'=│                                                                                       ░  ,▒╢╢╢╫╣▓▓▓▓▓▓▓▓▓▓▓██▓▓█▌   ▓▓▓█▓▓▓▓▓▓▓╣╣╢╣╣╢▒▒▒▒▒▒▒▒▒╖"⌐  ░      │" !_LF!
echo\ & <nul set /p "'=│    User: !User:~0,77!,`  ▄▓▓╣╣╫╣▓▒╢╣╢▓▓▓▓▓▓█████▓  ]▓▓▓▓▓▓╢╣╢╢╣╣╣╢╢╢╢╢╢╢╣╢▓╣@╢╣▒▒┐  \    │" !_LF!
echo\ & <nul set /p "'=│    Date: !Date_Time:~0,76!/   █▓▓▓▓▓▀`      ╙╙▓▓▓▓▓███▌@@▓╢╣╣▒▒▒▒▒▒▒▒╣▒╢▒ÑÑÑÑ╩╨╜╙▀▀▓▓▓▓▓Ç  ░   │" !_LF!
echo\ & <nul set /p "'=│    Updates: Please wait for the owner to update the system.                        ░   g▓█▀▀╙   ,,╓⌂⌂,µ,,,▄▄▓▓▓▓██╣▒█▓▓▓▓▓▓▓▓▓╣@p▄,                  ,`   │" !_LF!
echo\ & <nul set /p "'=│                                                                                    ░  ╙╙  ,╥H╬▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▀▀╣████▓▓▓▓▓▓▓▓▓▓▓███████▄▄▄▄▄▄▄g,   ",   │" !_LF!
echo\ & <nul set /p "'=│    CPU: !CPUName:~0,77!─ ╓▒▒▒▒▒▒▒╣▓▓▓▓▓▓▓███████████╫██▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓██▓▓██████████▌µ  \  │" !_LF!
echo\ & <nul set /p "'=│    Resolution: !Resolution:~0,71!g╢▒▒▒╢╫▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓╢▓▀█▓▓▓▓▓▓▌╙╙▀▓▓▓▓▓▓▓▓▓▓▓▀██▓▓▓▓███▄  ░ │" !_LF!
echo\ & <nul set /p "'=│    Memory: 8GB (1 out of 4 slots are used.)                                        ⌐  ▓▓╣▒▓▓▓▓▓▓▓▓▓▓█▀▀▀╙  ,▐▓▓▓▓▓▓███▓▀▓▓▓▓▓▓▓▓▄g ╙▀▀▓▓▓╣╣╣╢╢╢▓▓▓▓███  ░ │" !_LF!
echo\ & <nul set /p "'=│    Storage: 12.5GB of 128GB                                                        ⌐  ▓▓▓▓╣▓▓▓▓██▀▀`   ╓@╬╣╢▓▓▓██▓▒███████▓▓▓▓▓╢╢▓▓▓▄▄,   ╙╙╝▒▒▒▒▒▒▓▓▓  ] │" !_LF!
echo\ & <nul set /p "'=│    Graphics: !Graphics:~0,70!▒  ▓▓▓▓▓██▀▀    ,╥@╣╢▓▓▓████▓██████████▓▓▓▓▓▓▓▄▄▒▒╢▓▓▓▓▄,   ╙Ñ╖ ╙╫▓  ] │" !_LF!
echo\ & <nul set /p "'=│    Manufacturer: Amiercan Metagrands Inc.                                          ░  ▓▓▓██▀    ,φ▓╣╫▓▓▓████▓▓▓▓▓███▓▓▓████▀╙▀▀█▓▓▓▓█▓▓▓╢▓▓▓█▄    ╚, ▒  ░ │" !_LF!
echo\ & <nul set /p "'=│                                                                                    ░  ▓▓█"    ,▒▒╢╫▓▓▓███▓▓▓▀▀╙╩▓▓█▓▓▓▓▓▓▓██▄    ▀▓▓▓▓▓▓▓▓▓▓▓▓█▌µ   \r  ░ │" !_LF!
echo\ & <nul set /p "'=│    ─────────────────────────────────────────────                                   ▒  ▓▀     ╥▒▒╫▓▓▓▓▓▓▓▓▓▀    ▄▓██▓▓▓▓▓▓▓▓▓██▄    ╙▀▓▓▓▓▓██▓▓▓▓██▄    ,  │" !_LF!
echo\ & <nul set /p "'=│                                                                                    ░  `    ╓▒▒▒▒▓▓▓▓▓▓▓▓▀    ,▓▓██▓▓▓▓▓▓▓▓▓▓▓▓██▄    ╙▓▓▓▓▓▓▓███▓▓██▄  \  │" !_LF!
echo\ & <nul set /p "'=│                                                                                     ───  ,╣▒▒▒▒▓▓▓▓▓▓▓▀¬   ,▄▓▓█▓▓█▓▓▓▓▓▓▓██▓▓▓▓██▄    ╙▓▓╣▓▓▓▓██▓▓▓▓U j  │" !_LF!
echo\ & <nul set /p "'=│                                                                                       ░  ╠╣▒▒╫▓▓▓▓▓█▀╘    ▄█▓▓▓▓▓▓█▓▌▓▓▓▓▓▓▓▓███▓▓██▌,   ▀╣▒╢╢╣▓▓▓▓▓▓  ┌  │" !_LF!
echo\ & <nul set /p "'=│                                                                                        ,  ▐▒▒▓╢▓▓▓█'    ,▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌   ▀▓▓▓██▓▓███µ  "╣▒▒▒╢╣╢╢▓╩  ░  │" !_LF!
echo\ & <nul set /p "'=│                                                                                            ▓╣╢▓▓▓▌     ╔█▓▓▓╣▒╢▓▓▓▓▓▓▓▓▓▓     ╙▓▓▓██▓▓██▌   ╙⌐"╙▒▒▒╜  /   │" !_LF!
echo\ & <nul set /p "'=│                                                                                         ░  ╚▓╫▓▓█     á▓▓▓▓▒▒▓▀  ▓▓▌▓▓▓▓▓▌      ╟▓▓▓██▓███▄  "╖  ▒`  ░    │" !_LF!
echo\ & <nul set /p "'=│                                                                                          \  ▐▓▓█     ╓▓▓▓╣▒▒▓`   ▓▓▌█▓▓▓▓█▌      ╙▒▓▓▓█▓▓██µ  "▒╜   ░     │" !_LF!
echo\ & <nul set /p "'=│                                                                                           ,  ▀▓Ü    ┌▓▓▓╣╣╢▓    ▓▓▓▓█▓▓▓▓███▄     ╙▒╫▓▓▓▓▓██   "  ,`      │" !_LF!
echo\ & <nul set /p "'=│                                                                                            \  ▐     ▓▓▓▒╣╢▓▌   ▐▓╣▓▓▓▓▓▓▓████▌     ║▒▓▓▓▓▓▓█  ¡──'`       │" !_LF!
echo\ & <nul set /p "'=│                                                                                            ░  ┘    ╚▓▓╣╣╣╢▓   ▐▓▓╣╢▓▓█▓▓▓▓█████Ç    ▒╫▓▓▓▓▓╜  ░           │" !_LF!
echo\ & <nul set /p "'=│                                                                                             "───`\   ╙╩▄▒╣▓  ╔▓▓▓▓▓▓▓█▓▓▓▓▓█████    ]▒▓▓▓╙  ,"            │" !_LF!
echo\ & <nul set /p "'=│                                                                                                    '~   ╙▀▓▓╖╫▓▓▓▓▓█▓█▓▓▓▓▓▓████    ▓▓▓   ┌'              │" !_LF!
echo\ & <nul set /p "'=│                                                                                                    '─.   ╙╩▓▓▓▓███▓╣▓▓▓▓▓▓█▀`    ▀   ─'                   │" !_LF!
echo\ & <nul set /p "'=│                                                                                                        "~.   ▀▓███▒▒▓▓▓▀╙    ─└....─'                     │" !_LF!
echo\ & <nul set /p "'=│                                                                                                          '^^,  ▀██▒▒╜   .─``                               │" !_LF!
echo\ & <nul set /p "'=│                                                                                                              \  ▀▀   .─                                   │" !_LF!
echo\ & <nul set /p "'=│                                                                                                               ░....─'                                     │" !_LF!
echo\ & <nul set /p "'=└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘" !_LF!

%__AppDir__%timeout.exe -1 | echo\ & endlocal & cls & call wow.cmd

1.使用mode columns,lines定义在窗口/屏幕上显示文本所需的列数和行数:

%__AppDir__%mode.com con: cols=160 lines=40

观察1更换计算机时可能需要进行一些调整,因为某些类型的字体和/或大小/正文设置可能会干扰尺寸。


2.找出最长行的总长度,以及您的变量/文本将接收的编辑空间之间的精确长度,其中同一变量的值(长度)不同。

在此处输入图片描述

在此处输入图片描述

观察2定义行长时,请考虑在定义变量之前或之后以及/或在屏幕绘图中将字符定位在行上时留出一些空间


3.创建一个变量并从头到尾填充空格,总长度等于“屏幕上”最大行的长度

for /L %%L i (1 1 77)do set "_spc=!_spc! "

4.将相关命令中获得的变量与空格组成的变量连接起来

for /L %%L in (01 01 77)do set "_spc=!_spc! "

for /f usebackq^tokens^=4delims^=^>^< %%i in (`
     !_wmic! path Win32_VideoController get CurrentVerticalResolution^,CurrentHorizontalResolution /format:xml^|find "VALUE"
    `)do if "!Resolution!" == "" (set "Resolution=%%~i")else set "Resolution=!Resolution!x%%~i!_spc!"

...
     
for /f usebackq^tokens^=4delims^=^>^< %%i in (`
     !_wmic! path Win32_VideoController get Name /format:xml ^|find "VALUE"`)do set "Graphics=%%~i!_spc!"

...
     
for /f usebackq^tokens^=4delims^=^>^< %%i in (`
     !_wmic! path Win32_Processor get Name /format:xml ^|find "VALUE"`)do set "CPUName=%%~i!_spc!"

...

for /f usebackq^tokens^=4delims^=^>^< %%i in (`
     !_wmic! OS Get LocalDateTime /format:xml ^|find "VALUE"`)do set "_dt=%%~i"

set "User=%UserName%!_spc!
set "Date_Time=!_dt:~6,2!/!_dt:~4,2!/!_dt:~0,4! at !_dt:~8,2!:!_dt:~10,2!!_spc!"

5.最后要显示,只需将变量的长度限制为相应行的限制,我做了以下几行来举例说明

Line: Variable             Length       %Variable:~From,To-Length% 
User: %User%                77              %User:~0,77%
Date: %Date_Time%           76         %Date_Time:~0,76%
CPU: %CPUName%              77           %CPUName:~0,77%
Resolution: %Resolution%    71        %Resolution:~0,71%
Graphics: %Graphics%        70          %Graphics:~0,70%

观察3: 避免在绘图中使用转义字符,尤其是^%,问题的一部分是这些字符的存在而没有使用转义,即使在set /p命令中撰写......


观察数:4 Set /p保留正在执行命令的行,没有“换行符”,它会保留自身并执行其他命令,这也会将其保留在同一行...echo\解决了您的最大问题..


在此处输入图片描述

相关内容