英文:
How to get a split %var:~1,-2% with a ! or % in the string to echo correctly to a file. DELAYEDEXPANSION issue?
问题
I've translated the code section for you:
@ECHO OFF
CLS
SET "ramdisk=B:\"
CD /d "%~dp0"
SET titlename=UpdatingScoreboard
IF EXIST "%ramdisk%QUEUESB" (
TASKLIST /V /NH /FI "imagename eq cmd.exe"| find /I /C "%titlename%" > nul
if not errorlevel 1 exit /b
DEL "%ramdisk%QUEUESB" /F /Q >nul
)
TITLE %titlename%
IF EXIST "%ramdisk%UPDATINGSB" GOTO INPROGRESS
:BEGIN
ECHO.>"%ramdisk%UPDATINGSB"
SET UPLAYER=0
SET ACTIVENODES=0
SET NODENUM=1
SET MAXNODES=50
SET "lordfolder=C:\mystic\doors\lord"
SET "scorefile=%lordfolder%\score.ans"
SET "webfolder=C:\xampp\htdocs\gamedata"
CALL :fileheader
:checkdrops
IF %NODENUM% GTR %MAXNODES% GOTO completed
set "pathtodoorsys=C:\mystic\temp%NODENUM%\door.sys"
IF EXIST %pathtodoorsys% (
SET /A ACTIVENODES+=1
GOTO initsearch
)
SET /A NODENUM+=1
goto checkdrops
:initsearch
set player=0
set prevplayer=0
:startdump
CD /d "%ramdisk%"
"%~dp0playtext.exe " r %player% %player% %lordfolder%""
CD /d "%~dp0"
if %player% GEQ 1 (
fc "%ramdisk%playtext.%prevplayer%" "%ramdisk%playtext.%player%">"%ramdisk%searching.tmp1"
more +9 "%ramdisk%searching.tmp1">"%ramdisk%searching.tmp2"
set /a prevplayer+=1
)
set /a player+=1
if not exist "%ramdisk%searching.tmp2" goto startdump
for %%R in (%ramdisk%searching.tmp2) do if not %%~zR lss 1 goto startdump
set /a player-=1
set /a prevplayer-=1
del "%ramdisk%playtext.%player%" /f /q >nul
del "%ramdisk%playtext.%prevplayer%" /f /q >nul
DEL "%ramdisk%searching.tm*" /F /Q >nul
set /a prevplayer-=1
CALL :get-activeuser activeuser
:parsenames
IF NOT EXIST "%ramdisk%playtext.%prevplayer%" SET /A NODENUM+=1 & SET /A UPLAYER+=1 & goto checkdrops
CALL :get-username username
CALL :trim loginname %username:~9%
IF /I "%activeuser%"=="%loginname%" (
CALL :get-playername playername
CALL :filecontent
SET /A NODENUM+=1
goto checkdrops
)
set /a prevplayer-=1
GOTO parsenames
:get-activeuser
for /f "usebackq skip=9 eol= delims=" %%a in ("%pathtodoorsys%") do (
set "%1=%%a"
exit /b
)
exit /b
:get-username
for /f "usebackq skip=2 eol= delims=" %%a in ("%ramdisk%playtext.%prevplayer%") do (
set "%1=%%a"
exit /b
)
exit /b
:get-playername
for /f "usebackq skip=1 eol= delims=" %%a in ("%ramdisk%playtext.%prevplayer%") do (
set "%1=%%a"
exit /b
)
exit /b
:trim
SETLOCAL ENABLEDELAYEDEXPANSION
SET trim=%*
FOR /f "tokens=1*" %%a in ("!trim!") DO ENDLOCAL & set %1=%%b
exit /b
:completed
SET NODENUM=0
SET MAXUSERS=150
IF NOT %ACTIVENODES% GTR 0 (
ECHO ^0>"%webfolder%\online.txt"
call :filefooter
call :cleanup
more +4 "%scorefile%" > "%ramdisk%score.tmp"
powershell -executionpolicy unrestricted -file "%ramdisk%showonline.ps1"
del "%ramdisk%score.tmp" /f /q >nul
del "%ramdisk%showonline.ps1" /f /q >nul
IF EXIST "%ramdisk%QUEUESB" (
DEL "%ramdisk%QUEUESB" /F /Q >nul
) else (
DEL "%ramdisk%UPDATINGSB" /F /Q >nul
)
exit /b
) ELSE (
ECHO ^1>"%webfolder%\online.txt"
call :filefooter
<details>
<summary>英文:</summary>
The **:FileContent** function near the bottom is where the variable I'm having issues with is.
**!onlineplayer!** is the variable I need to pass a string that may include `!` or `%` to a file via `>>`
Output I want:
`5John `%Wheeler
Output I get:
`5John `Wheeler
I need to pipe the value to a text file (PowerShell) for execution at the end of the script.
Everything works correctly, until I use a value containing a `!` or a `%`, then not surprisingly I end up getting empty space where they are supposed to be, normally I would just escape/double `^!` or `%%` but I have no control over the var value and I´m not sure if I should make a new section that tries to inject another `%` into the `txt` file if its detected, or if this already works but just has an expansion issue? I don´t know that an injection route would be easier or without problems.
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
CLS
CD /d %~dp0
SET titlename=UpdatingScoreboard
IF EXIST QUEUESB (
TASKLIST /V /NH /FI "imagename eq cmd.exe"| find /I /C "%titlename%" > nul
IF %errorlevel%==0 exit /b
DEL QUEUESB /F /Q >nul
)
TITLE %titlename%
IF EXIST UPDATINGSB GOTO INPROGRESS
:BEGIN
ECHO.>UPDATINGSB
SET UPLAYER=0
SET ACTIVENODES=0
SET NODENUM=1
SET MAXNODES=50
SET "lordfolder=C:\mystic\doors\lord"
SET "webfolder=C:\xampp\htdocs\gamedata"
CALL :newfile
CALL :fileheader
:checkdrops
IF %NODENUM% GTR %MAXNODES% GOTO completed
set "pathtodoorsys=C:\mystic\temp%NODENUM%\door.sys"
IF EXIST %pathtodoorsys% (
SET /A ACTIVENODES=%ACTIVENODES%+1
GOTO initsearch
)
SET /A NODENUM=%NODENUM%+1
goto checkdrops
:initsearch
set player=0
set prevplayer=0
:startdump
playtext r %player% %player% %lordfolder%
if %player% GEQ 1 (
fc playtext.%prevplayer% playtext.%player%>searching.tmp1
more +9 searching.tmp1>searching.tmp2
set /a prevplayer=%prevplayer%+1
)
set /a player=%player%+1
if not exist searching.tmp2 goto startdump
for %%R in (searching.tmp2) do if not %%~zR lss 1 goto startdump
set /a player=%player%-1
set /a prevplayer=%prevplayer%-1
del playtext.%player% /f /q >nul
del playtext.%prevplayer% /f /q >nul
DEL searching.tm* /F /Q >nul
set /a prevplayer=%prevplayer%-1
CALL :get-activeuser activeuser
:parsenames
IF NOT EXIST "playtext.%prevplayer%" SET /A NODENUM=%NODENUM%+1 & SET /A UPLAYER=%UPLAYER%+1 & goto checkdrops
CALL :get-username username
IF /I "%activeuser%"=="%username:~9,-2%" (
CALL :get-playername playername
SET "onlineplayer=!playername:~5!"
CALL :filecontent
SET /A NODENUM=%NODENUM%+1
goto checkdrops
)
IF /I "%activeuser%"=="%username:~9,-1%" (
CALL :get-playername playername
SET "onlineplayer=!playername:~5!"
CALL :filecontent
SET /A NODENUM=%NODENUM%+1
goto checkdrops
)
set /a prevplayer=%prevplayer%-1
GOTO parsenames
:get-activeuser
for /f "skip=9 eol= delims=" %%a in ('type "%pathtodoorsys%"') do (
set "%1=%%a"
exit /b
)
exit /b
:get-username
for /f "skip=2 eol= delims=" %%a in ('type "playtext.%prevplayer%"') do (
set "%1=%%a"
exit /b
)
exit /b
:get-playername
for /f "skip=1 eol= delims=" %%a in ('type "playtext.%prevplayer%"') do (
set "%1=%%a"
exit /b
)
exit /b
:completed
SET NODENUM=0
SET MAXUSERS=150
IF NOT %ACTIVENODES% GTR 0 (
ECHO ^0>"%webfolder%\online.txt"
call :filefooter
call :cleanup
more +4 "%lordfolder%\score.ans" > "%lordfolder%\score.tmp"
powershell -executionpolicy unrestricted -file "%~dp0showonline.ps1"
del "%lordfolder%\score.tmp" /f /q >nul
del "%~dp0showonline.ps1" /f /q >nul
IF EXIST QUEUESB (
DEL QUEUESB /F /Q >nul
) else (
DEL UPDATINGSB /F /Q >nul
)
exit /b
) ELSE (
ECHO ^1>"%webfolder%\online.txt"
call :filefooter
call :cleanup
more +4 "%lordfolder%\score.ans" > "%lordfolder%\score.tmp"
powershell -executionpolicy unrestricted -file "%~dp0showonline.ps1"
IF %uplayer% GEQ 1 (
CALL :uplayer
)
del "%lordfolder%\score.tmp" /f /q >nul
del "%~dp0showonline.ps1" /f /q >nul
IF EXIST QUEUESB (
DEL QUEUESB /F /Q >nul
) else (
DEL UPDATINGSB /F /Q >nul
)
exit /b
)
:cleanup
if %NODENUM% GTR %MAXUSERS% exit /b
if exist playtext.%NODENUM% del playtext.%NODENUM% /F /Q >nul
set /a NODENUM=%NODENUM%+1
goto cleanup
exit /b
:NEWFILE
IF EXIST showonline.ps1 DEL showonline.ps1 /F /Q >nul
exit /b
:FILEHEADER
ECHO Get-Content %lordfolder%\score.tmp ^| ForEach-Object {>> showonline.ps1
ECHO $line = $>> showonline.ps1
ECHO $line = $ -replace ' ', '^ ' -replace '(\x1B)', '' -replace '([)', '' -replace '0;30m', '^</font^>^<font color="Black"^>' -replace '0;31m', '^</font^>^<font color="DarkRed"^>' -replace '0;32m', '^</font^>^<font color="Green"^>' -replace '0;33m', '^</font^>^<font color="Orange"^>' -replace '0;34m', '^</font^>^<font color="DarkBlue"^>' -replace '0;35m', '^</font^>^<font color="DarkMagenta"^>' -replace '0;36m', '^</font^>^<font color="DarkCyan"^>' -replace '0;37m', '^</font^>^<font color="Gray"^>' -replace '1;30m', '^</font^>^<font color="DimGray"^>' -replace '1;31m', '^</font^>^<font color="Red"^>' -replace '1;32m', '^</font^>^<font color="LightGreen"^>' -replace '1;33m', '^</font^>^<font color="Yellow"^>' -replace '1;34m', '^</font^>^<font color="Blue"^>' -replace '1;35m', '^</font^>^<font color="Magenta"^>' -replace '1;36m', '^</font^>^<font color="Cyan"^>' -replace '1;37m', '^</font^>^<font color="White"^>' -replace '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-', '^<font color="LightGreen"^>-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-^</font^>' -replace '^ ^</font^>^<font color="White"^>On', '^</font^>^<font class="blink" color="Red"^>On^</font^>' -replace '\S^+$','$^&^<br^>' -replace 'Alive^<br^>','Alive^ ^<br^>'>> showonline.ps1
exit /b
:FILECONTENT
ECHO $a = "!onlineplayer!">> showonline.ps1
ECHO $a = $a.replace('0','\x1B\[1;32m').replace('
1','\x1B[0;34m').replace('2','\x1B\[0;32m').replace('
3','\x1B[0;36m').replace('4','\x1B\[0;31m').replace('
5','\x1B[0;35m').replace('6','\x1B\[0;33m').replace('
7','\x1B[0;37m').replace('8','\x1B\[1;30m').replace('
9','\x1B[1;34m').replace('#','\x1B\[1;35m').replace('
$','\x1B[1;33m').replace('@','\x1B\[1;31m').replace('
^^!','\x1B[1;36m').replace('`%%','\x1B[1;37m')>> showonline.ps1
ECHO if ($_ -like "$a") {>> showonline.ps1
ECHO $line = $_ -replace ' ', '^ ' -replace '(\x1B)', '' -replace '([)', '' -replace '0;30m', '^</font^>^<font color="Black"^>' -replace '0;31m', '^</font^>^<font color="DarkRed"^>' -replace '0;32m', '^</font^>^<font color="Green"^>' -replace '0;33m', '^</font^>^<font color="Orange"^>' -replace '0;34m', '^</font^>^<font color="DarkBlue"^>' -replace '0;35m', '^</font^>^<font color="DarkMagenta"^>' -replace '0;36m', '^</font^>^<font color="DarkCyan"^>' -replace '0;37m', '^</font^>^<font color="Gray"^>' -replace '1;30m', '^</font^>^<font color="DimGray"^>' -replace '1;31m', '^</font^>^<font color="Red"^>' -replace '1;32m', '^</font^>^<font color="LightGreen"^>' -replace '1;33m', '^</font^>^<font color="Yellow"^>' -replace '1;34m', '^</font^>^<font color="Blue"^>' -replace '1;35m', '^</font^>^<font color="Magenta"^>' -replace '1;36m', '^</font^>^<font color="Cyan"^>' -replace '1;37m', '^</font^>^<font color="White"^>' -replace '^ ^</font^>^<font color="White"^>On', '^</font^>^<font class="blink" color="Red"^>On^</font^>' -replace '\S^+$','$^&^<br^>' -replace 'Alive^<br^>','Alive^ ^<br^>' -replace 'Alive^ ^<br^>', 'Alive^ ^</font^>^<font class="blink" color="Red"^>On^</font^>^<br^>' -replace 'Dead^ ^<br^>', 'Dead^ ^ ^</font^>^<font class="blink" color="Red"^>On^</font^>^<br^>'>> showonline.ps1
ECHO }>> showonline.ps1
exit /b
:FILEFOOTER
ECHO $line>> showonline.ps1
ECHO ^} ^| Set-Content %webfolder%\score.shtml>> showonline.ps1
exit /b
:uplayer
ECHO ^<br^>^<center^>^<font class="blink" color="Red"^>A hero is approaching.. Will they join our ranks^?^</font^>^</center^>>>%webfolder%\score.shtml
exit /b
:INPROGRESS
IF NOT EXIST QUEUESB ECHO.>QUEUESB
ping 127.0.0.1 -n 2 > nul
SET /A WAITEDTIME=%WAITEDTIME%+1
IF %WAITEDTIME% GEQ 8 DEL UPDATINGSB /F /Q >nul
IF EXIST UPDATINGSB GOTO INPROGRESS
DEL QUEUESB /F /Q >nul
GOTO BEGIN
**FIXED BY MOVING DELAYED EXPANSION TO OUTPUT SECTION ONLY**
Updated working code with some of the commented fixes applied. I can improve it more but I need to make sure what im doing with it isnt a waste of time first, please excuse the sloppyness.
@ECHO OFF
CLS
SET "ramdisk=B:"
CD /d "%~dp0"
SET titlename=UpdatingScoreboard
IF EXIST "%ramdisk%QUEUESB" (
TASKLIST /V /NH /FI "imagename eq cmd.exe"| find /I /C "%titlename%" > nul
if not errorlevel 1 exit /b
DEL "%ramdisk%QUEUESB" /F /Q >nul
)
TITLE %titlename%
IF EXIST "%ramdisk%UPDATINGSB" GOTO INPROGRESS
:BEGIN
ECHO.>"%ramdisk%UPDATINGSB"
SET UPLAYER=0
SET ACTIVENODES=0
SET NODENUM=1
SET MAXNODES=50
SET "lordfolder=C:\mystic\doors\lord"
SET "scorefile=%lordfolder%\score.ans"
SET "webfolder=C:\xampp\htdocs\gamedata"
CALL :fileheader
:checkdrops
IF %NODENUM% GTR %MAXNODES% GOTO completed
set "pathtodoorsys=C:\mystic\temp%NODENUM%\door.sys"
IF EXIST %pathtodoorsys% (
SET /A ACTIVENODES+=1
GOTO initsearch
)
SET /A NODENUM+=1
goto checkdrops
:initsearch
set player=0
set prevplayer=0
:startdump
CD /d "%ramdisk%"
"%~dp0playtext.exe " r %player% %player% %lordfolder%""
CD /d "%~dp0
if %player% GEQ 1 (
fc "%ramdisk%playtext.%prevplayer%" "%ramdisk%playtext.%player%">"%ramdisk%searching.tmp1"
more +9 "%ramdisk%searching.tmp1">"%ramdisk%searching.tmp2"
set /a prevplayer+=1
)
set /a player+=1
if not exist "%ramdisk%searching.tmp2" goto startdump
for %%R in (%ramdisk%searching.tmp2) do if not %%~zR lss 1 goto startdump
set /a player-=1
set /a prevplayer-=1
del "%ramdisk%playtext.%player%" /f /q >nul
del "%ramdisk%playtext.%prevplayer%" /f /q >nul
DEL "%ramdisk%searching.tm*" /F /Q >nul
set /a prevplayer-=1
CALL :get-activeuser activeuser
:parsenames
IF NOT EXIST "%ramdisk%playtext.%prevplayer%" SET /A NODENUM+=1 & SET /A UPLAYER+=1 & goto checkdrops
CALL :get-username username
CALL :trim loginname %username:~9%
IF /I "%activeuser%"=="%loginname%" (
CALL :get-playername playername
CALL :filecontent
SET /A NODENUM+=1
goto checkdrops
)
set /a prevplayer-=1
GOTO parsenames
:get-activeuser
for /f "usebackq skip=9 eol= delims=" %%a in ("%pathtodoorsys%") do (
set "%1=%%a"
exit /b
)
exit /b
:get-username
for /f "usebackq skip=2 eol= delims=" %%a in ("%ramdisk%playtext.%prevplayer%") do (
set "%1=%%a"
exit /b
)
exit /b
:get-playername
for /f "usebackq skip=1 eol= delims=" %%a in ("%ramdisk%playtext.%prevplayer%") do (
set "%1=%%a"
exit /b
)
exit /b
:trim
SETLOCAL ENABLEDELAYEDEXPANSION
SET trim=%*
FOR /f "tokens=1*" %%a in ("!trim!") DO ENDLOCAL & set %1=%%b
exit /b
:completed
SET NODENUM=0
SET MAXUSERS=150
IF NOT %ACTIVENODES% GTR 0 (
ECHO ^0>"%webfolder%\online.txt"
call :filefooter
call :cleanup
more +4 "%scorefile%" > "%ramdisk%score.tmp"
powershell -executionpolicy unrestricted -file "%ramdisk%showonline.ps1"
del "%ramdisk%score.tmp" /f /q >nul
del "%ramdisk%showonline.ps1" /f /q >nul
IF EXIST "%ramdisk%QUEUESB" (
DEL "%ramdisk%QUEUESB" /F /Q >nul
) else (
DEL "%ramdisk%UPDATINGSB" /F /Q >nul
)
exit /b
) ELSE (
ECHO ^1>"%webfolder%\online.txt"
call :filefooter
call :cleanup
more +4 "%scorefile%" > "%ramdisk%score.tmp"
powershell -executionpolicy unrestricted -file "%ramdisk%showonline.ps1"
IF %uplayer% GEQ 1 (
CALL :uplayer
)
del "%ramdisk%score.tmp" /f /q >nul
del "%ramdisk%showonline.ps1" /f /q >nul
IF EXIST "%ramdisk%QUEUESB" (
DEL "%ramdisk%QUEUESB" /F /Q >nul
) else (
DEL "%ramdisk%UPDATINGSB" /F /Q >nul
)
exit /b
)
:cleanup
if %NODENUM% GTR %MAXUSERS% exit /b
if exist "%ramdisk%playtext.%NODENUM%" del "%ramdisk%playtext.%NODENUM%" /F /Q >nul
set /a NODENUM+=1
goto cleanup
exit /b
:FILEHEADER
ECHO Get-Content "%ramdisk%score.tmp" ^| ForEach-Object {> %ramdisk%showonline.ps1
ECHO $line = $>> %ramdisk%showonline.ps1
ECHO $line = $ -replace ' ', '^ ' -replace '(\x1B)', '' -replace '([)', '' -replace '0;30m', '^</font^>^<font color="Black"^>' -replace '0;31m', '^</font^>^<font color="#b30000"^>' -replace '0;32m', '^</font^>^<font color="Green"^>' -replace '0;33m', '^</font^>^<font color="Orange"^>' -replace '0;34m', '^</font^>^<font color="Blue"^>' -replace '0;35m', '^</font^>^<font color="DarkMagenta"^>' -replace '0;36m', '^</font^>^<font color="DarkCyan"^>' -replace '0;37m', '^</font^>^<font color="Silver"^>' -replace '1;30m', '^</font^>^<font color="DimGray"^>' -replace '1;31m', '^</font^>^<font color="#ff4d4d"^>' -replace '1;32m', '^</font^>^<font color="#00cc00"^>' -replace '1;33m', '^</font^>^<font color="Yellow"^>' -replace '1;34m', '^</font^>^<font color="#4d4dff"^>' -replace '1;35m', '^</font^>^<font color="#ff66ff"^>' -replace '1;36m', '^</font^>^<font color="Cyan"^>' -replace '1;37m', '^</font^>^<font color="White"^>' -replace '^ ^</font^>^<font color="White"^>On', '^</font^>^<font class="blink" color="Red"^>On^</font^>' -replace '\S^+$','$^&^<br^>' -replace 'Alive^<br^>','Alive^ ^<br^>' -replace '^</font^>^<font color="#00cc00"^>-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-^<br^>','^</font^>^<div id="headerline"^>^<font color="#00cc00"^>-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-^</font^>^</div^>'>> %ramdisk%showonline.ps1
exit /b
:FILECONTENT
SETLOCAL ENABLEDELAYEDEXPANSION
ECHO $a = '!playername:~5!'>> %ramdisk%showonline.ps1
ENDLOCAL
ECHO $a = $a.replace(' ','^').replace('0','^*').replace('
1','^').replace('2','^*').replace('
3','^').replace('4','^*').replace('
5','^').replace('6','^*').replace('
7','^').replace('8','^*').replace('
9','^').replace('#','^*').replace('
$','').replace('@','').replace('
!','^').replace('`%%','^') >> %ramdisk%showonline.ps1
ECHO if ($_ -like "$a") {>> %ramdisk%showonline.ps1
ECHO $line = $_ -replace ' ', '^ ' -replace '(\x1B)', '' -replace '([)', '' -replace '0;30m', '^</font^>^<font color="Black"^>' -replace '0;31m', '^</font^>^<font color="#b30000"^>' -replace '0;32m', '^</font^>^<font color="Green"^>' -replace '0;33m', '^</font^>^<font color="Orange"^>' -replace '0;34m', '^</font^>^<font color="Blue"^>' -replace '0;35m', '^</font^>^<font color="DarkMagenta"^>' -replace '0;36m', '^</font^>^<font color="DarkCyan"^>' -replace '0;37m', '^</font^>^<font color="Silver"^>' -replace '1;30m', '^</font^>^<font color="DimGray"^>' -replace '1;31m', '^</font^>^<font color="#ff4d4d"^>' -replace '1;32m', '^</font^>^<font color="#00cc00"^>' -replace '1;33m', '^</font^>^<font color="Yellow"^>' -replace '1;34m', '^</font^>^<font color="#4d4dff"^>' -replace '1;35m', '^</font^>^<font color="#ff66ff"^>' -replace '1;36m', '^</font^>^<font color="Cyan"^>' -replace '1;37m', '^</font^>^<font color="White"^>' -replace '^ ^</font^>^<font color="White"^>On', '^</font^>^<font class="blink" color="Red"^>On^</font^>' -replace '\S^+$','$^&^<br^>' -replace 'Alive^<br^>','Alive^ ^<br^>' -replace 'Alive^ ^<br^>', 'Alive^ ^</font^>^<font class="blink" color="Red"^>On^</font^>^<br^>' -replace 'Dead^ ^<br^>', 'Dead^ ^ ^</font^>^<font class="blink" color="Red"^>On^</font^>^<br^>'>> %ramdisk%showonline.ps1
ECHO }>> %ramdisk%showonline.ps1
exit /b
:FILEFOOTER
ECHO $line>> %ramdisk%showonline.ps1
ECHO ^} ^| Set-Content %webfolder%\score.shtml>> %ramdisk%showonline.ps1
exit /b
:uplayer
ECHO ^<br^>^<center^>^<font class="blink" color="Red"^>A hero is approaching.. Will they join our ranks^?^</font^>^</center^>>>%webfolder%\score.shtml
exit /b
:INPROGRESS
IF NOT EXIST "%ramdisk%QUEUESB" ECHO.>"%ramdisk%QUEUESB"
ping 127.0.0.1 -n 2 > nul
SET /A WAITEDTIME+=1
IF %WAITEDTIME% GEQ 8 DEL "%ramdisk%UPDATINGSB" /F /Q >nul
IF EXIST "%ramdisk%UPDATINGSB" GOTO INPROGRESS
DEL "%ramdisk%QUEUESB" /F /Q >nul
GOTO BEGIN
</details>
# 答案1
**得分**: 0
使用延迟扩展将`ECHO $a = "!playername:~5!" >> showonline.ps1` 包裹在`:FILECONTENT`函数中解决了问题。楼主已更新帖子。没有评论的帮助,我无法解决这个问题。谢谢!
<details>
<summary>英文:</summary>
Wrapping only a single line in the :FILECONTENT function with delayed expansion resolved the issue. OP updated. I could not have solved this without the comments. Thank you!
SETLOCAL ENABLEDELAYEDEXPANSION
ECHO $a = "!playername:~5!">> showonline.ps1
ENDLOCAL
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论