Files
claudetools/check-dos-compatibility.ps1
Mike Swanson 80add06dda 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>
2026-01-19 17:59:28 -07:00

75 lines
3.5 KiB
PowerShell

# Comprehensive DOS 6.22 compatibility checker
# Scans all BAT files for incompatible commands
$BATFiles = Get-ChildItem *.BAT | Where-Object { $_.Name -notlike "*_FROM_*" -and $_.Name -notlike "*_TEST*" -and $_.Name -notlike "*_VERIFY*" -and $_.Name -notlike "*_CHECK*" -and $_.Name -notlike "*_MONITOR*" }
Write-Host "========================================" -ForegroundColor Red
Write-Host "DOS 6.22 COMPATIBILITY CHECK" -ForegroundColor Red
Write-Host "========================================" -ForegroundColor Red
Write-Host ""
$TotalIssues = 0
# DOS 6.22 INCOMPATIBLE patterns
$IncompatiblePatterns = @(
@{Pattern='SET\s+/P'; Description='SET /P (interactive input) - NOT in DOS 6.22'},
@{Pattern='SET\s+/A'; Description='SET /A (arithmetic) - NOT in DOS 6.22'},
@{Pattern='IF\s+/I'; Description='IF /I (case-insensitive) - NOT in DOS 6.22'},
@{Pattern='FOR\s+/F'; Description='FOR /F (parse files) - NOT in DOS 6.22'},
@{Pattern='FOR\s+/L'; Description='FOR /L (loop) - NOT in DOS 6.22'},
@{Pattern='FOR\s+/D'; Description='FOR /D (directories) - NOT in DOS 6.22'},
@{Pattern='FOR\s+/R'; Description='FOR /R (recursive) - NOT in DOS 6.22'},
@{Pattern='GOTO\s+:EOF'; Description='GOTO :EOF - NOT in DOS 6.22 (use GOTO END)'},
@{Pattern='%COMPUTERNAME%'; Description='%COMPUTERNAME% - NOT in DOS 6.22'},
@{Pattern='%USERNAME%'; Description='%USERNAME% - NOT in DOS 6.22'},
@{Pattern='%USERPROFILE%'; Description='%USERPROFILE% - NOT in DOS 6.22'},
@{Pattern='&&'; Description='&& operator - NOT in DOS 6.22'},
@{Pattern='\|\|'; Description='|| operator - NOT in DOS 6.22'},
@{Pattern='\\NUL(?!\s|$)'; Description='\NUL as filename - INVALID (use \*.* for directory test)'},
@{Pattern='XCOPY.*\/Q'; Description='XCOPY /Q (quiet mode) - NOT in DOS 6.22'},
@{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='^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='START\s+'; Description='START command - NOT in DOS 6.22'}
)
foreach ($File in $BATFiles) {
Write-Host "Checking: $($File.Name)" -ForegroundColor Cyan
$Content = Get-Content $File.FullName
$FileIssues = 0
foreach ($Pattern in $IncompatiblePatterns) {
$LineNum = 0
foreach ($Line in $Content) {
$LineNum++
if ($Line -match $Pattern.Pattern) {
if ($FileIssues -eq 0) {
Write-Host ""
}
Write-Host " [ERROR] Line $LineNum : $($Pattern.Description)" -ForegroundColor Red
Write-Host " > $Line" -ForegroundColor Yellow
$FileIssues++
$TotalIssues++
}
}
}
if ($FileIssues -eq 0) {
Write-Host " [OK] No incompatibilities found" -ForegroundColor Green
}
Write-Host ""
}
Write-Host "========================================" -ForegroundColor Red
Write-Host "TOTAL ISSUES FOUND: $TotalIssues" -ForegroundColor Red
Write-Host "========================================" -ForegroundColor Red
if ($TotalIssues -gt 0) {
Write-Host ""
Write-Host "ACTION REQUIRED: Fix all incompatibilities before deployment" -ForegroundColor Red
}