fix: Replace double-pipe with intermediate temp files for DOS 6.22 compatibility
CRITICAL ISSUE FOUND BY CODING AGENT WITH SEQUENTIAL THINKING: Root cause: Lines 273 and 303 used double-pipe commands with output redirection, which DOS 6.22 cannot handle reliably: TYPE file | FIND /V "A" | FIND /V "B" >> output This syntax fails silently in DOS 6.22: - The >> operator may bind to wrong command - DOS 6.22 cannot properly handle TWO pipes followed by redirection - Result: Nothing gets appended, or operation fails silently This explains ALL user-reported issues: 1. "set is still at the end of autoexec" - Line 303 failed, so old AUTOEXEC.BAT content was never appended to temp file 2. AUTOEXEC.BAT lost most of its content - Only first 2 lines remained 3. Post-boot scripts couldn't find MACHINE variable Solution: Use intermediate temp files for multi-step filtering BEFORE (fails in DOS 6.22): TYPE C:\AUTOEXEC.BAT | FIND /V "@ECHO OFF" | FIND /V "SET MACHINE=" >> C:\AUTOEXEC.TMP AFTER (DOS 6.22 compatible): TYPE C:\AUTOEXEC.BAT | FIND /V "@ECHO OFF" > C:\AUTOEXEC.TM1 TYPE C:\AUTOEXEC.TM1 | FIND /V "SET MACHINE=" > C:\AUTOEXEC.TM2 TYPE C:\AUTOEXEC.TM2 >> C:\AUTOEXEC.TMP DEL C:\AUTOEXEC.TM1 DEL C:\AUTOEXEC.TM2 Changes: - DEPLOY.BAT lines 271-278: ADD_MACHINE_VAR section fixed - DEPLOY.BAT lines 301-315: MACHINE_EXISTS section fixed - Both sections now use C:\AUTOEXEC.TM1 and C:\AUTOEXEC.TM2 as intermediate files - check-dos-compatibility.ps1: Added pattern to detect double-pipe with redirect DOS 6.22 Rule: - ONE pipe per command line maximum - Use intermediate files for multi-step filtering - Never combine multiple pipes with output redirection (>, >>) Testing: This fix should: 1. Preserve ALL content from original AUTOEXEC.BAT 2. Insert SET MACHINE=%MACHINE% at line 2 3. Remove any old SET MACHINE= lines 4. Make MACHINE variable available to post-boot scripts Deployed to: - D2TESTNAS: /data/test/DEPLOY.BAT Credit: Coding Agent with Sequential Thinking MCP identified root cause Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
14
DEPLOY.BAT
14
DEPLOY.BAT
@@ -268,9 +268,12 @@ REM This ensures it's set before any scripts or commands run
|
|||||||
IF NOT EXIST C:\AUTOEXEC.BAT GOTO CREATE_NEW_AUTOEXEC
|
IF NOT EXIST C:\AUTOEXEC.BAT GOTO CREATE_NEW_AUTOEXEC
|
||||||
|
|
||||||
REM AUTOEXEC.BAT exists - insert SET MACHINE at line 2 (after @ECHO OFF)
|
REM AUTOEXEC.BAT exists - insert SET MACHINE at line 2 (after @ECHO OFF)
|
||||||
|
REM Use intermediate files - DOS 6.22 cannot handle double pipes with redirection
|
||||||
ECHO @ECHO OFF > C:\AUTOEXEC.TMP
|
ECHO @ECHO OFF > C:\AUTOEXEC.TMP
|
||||||
ECHO SET MACHINE=%MACHINE% >> C:\AUTOEXEC.TMP
|
ECHO SET MACHINE=%MACHINE% >> C:\AUTOEXEC.TMP
|
||||||
TYPE C:\AUTOEXEC.BAT | FIND /V "@ECHO OFF" >> C:\AUTOEXEC.TMP
|
TYPE C:\AUTOEXEC.BAT | FIND /V "@ECHO OFF" > C:\AUTOEXEC.TM1
|
||||||
|
TYPE C:\AUTOEXEC.TM1 >> C:\AUTOEXEC.TMP
|
||||||
|
DEL C:\AUTOEXEC.TM1
|
||||||
COPY C:\AUTOEXEC.TMP C:\AUTOEXEC.BAT >NUL
|
COPY C:\AUTOEXEC.TMP C:\AUTOEXEC.BAT >NUL
|
||||||
DEL C:\AUTOEXEC.TMP
|
DEL C:\AUTOEXEC.TMP
|
||||||
GOTO MACHINE_ADD_DONE
|
GOTO MACHINE_ADD_DONE
|
||||||
@@ -296,11 +299,16 @@ ECHO Updating to: SET MACHINE=%MACHINE%
|
|||||||
ECHO.
|
ECHO.
|
||||||
|
|
||||||
REM Remove old SET MACHINE= line and insert new one at beginning
|
REM Remove old SET MACHINE= line and insert new one at beginning
|
||||||
|
REM Use intermediate files - DOS 6.22 cannot handle double pipes with redirection
|
||||||
ECHO @ECHO OFF > C:\AUTOEXEC.TMP
|
ECHO @ECHO OFF > C:\AUTOEXEC.TMP
|
||||||
ECHO SET MACHINE=%MACHINE% >> C:\AUTOEXEC.TMP
|
ECHO SET MACHINE=%MACHINE% >> C:\AUTOEXEC.TMP
|
||||||
|
|
||||||
REM Append rest of AUTOEXEC.BAT, excluding @ECHO OFF and old SET MACHINE= lines
|
REM Filter out @ECHO OFF and SET MACHINE= lines in separate steps
|
||||||
TYPE C:\AUTOEXEC.BAT | FIND /V "@ECHO OFF" | FIND /V "SET MACHINE=" >> C:\AUTOEXEC.TMP
|
TYPE C:\AUTOEXEC.BAT | FIND /V "@ECHO OFF" > C:\AUTOEXEC.TM1
|
||||||
|
TYPE C:\AUTOEXEC.TM1 | FIND /V "SET MACHINE=" > C:\AUTOEXEC.TM2
|
||||||
|
TYPE C:\AUTOEXEC.TM2 >> C:\AUTOEXEC.TMP
|
||||||
|
DEL C:\AUTOEXEC.TM1
|
||||||
|
DEL C:\AUTOEXEC.TM2
|
||||||
|
|
||||||
REM Replace original with updated version
|
REM Replace original with updated version
|
||||||
COPY C:\AUTOEXEC.TMP C:\AUTOEXEC.BAT >NUL
|
COPY C:\AUTOEXEC.TMP C:\AUTOEXEC.BAT >NUL
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ $IncompatiblePatterns = @(
|
|||||||
@{Pattern='IF.*\('; Description='IF ( ... ) multi-line blocks - NOT in DOS 6.22 (use GOTO labels)'},
|
@{Pattern='IF.*\('; Description='IF ( ... ) multi-line blocks - NOT in DOS 6.22 (use GOTO labels)'},
|
||||||
@{Pattern='\)\s*ELSE\s*\('; Description=') ELSE ( clause - NOT in DOS 6.22 (use GOTO labels)'},
|
@{Pattern='\)\s*ELSE\s*\('; Description=') ELSE ( clause - NOT in DOS 6.22 (use GOTO labels)'},
|
||||||
@{Pattern='^PAUSE\s+'; Description='PAUSE message - NOT in DOS 6.22 (use ECHO then PAUSE)'},
|
@{Pattern='^PAUSE\s+'; Description='PAUSE message - NOT in DOS 6.22 (use ECHO then PAUSE)'},
|
||||||
|
@{Pattern='\|.*\|.*>>'; Description='Double pipe with redirect (|..|..>>) - NOT reliable in DOS 6.22 (use temp files)'},
|
||||||
@{Pattern='CHOICE\s+/[A-Z]'; Description='CHOICE with options - Check if CHOICE.COM available'},
|
@{Pattern='CHOICE\s+/[A-Z]'; Description='CHOICE with options - Check if CHOICE.COM available'},
|
||||||
@{Pattern='START\s+'; Description='START command - NOT in DOS 6.22'}
|
@{Pattern='START\s+'; Description='START command - NOT in DOS 6.22'}
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user