Hi Jeb,
I was afraid you’d say something like that.
But it’s even worse than I originally thought. If the program is executed from the command line using cmd like so:
Code: Select all
cmd /c prog.cmd "quoted ^ carets" unquoted ^^^^ carets
The carets must be escaped
a second time for the command line cmd. So the quoted carets are doubled and the unquoted ones are
quartered in this case.
Btw, please post a link to an explanation of the technique for using rem in a plain for loop to capture the contents of %*.
Here’s my code so far, Carlos:
Code: Select all
@echo off & setlocal enableextensions disabledelayedexpansion
echo on
rem # %* #
@echo off
set "arg1=%~1"
if defined arg1 (set arg1 | findstr /ilvx arg1=/ansi >nul && (
set "arg1="
cmd /d /a /c call "%~dpnx0" /ansi %* && goto end || goto die
)) else (>&2 echo(filename(s^) expected & goto die)
shift /1
(call;)
echo(prog in ansi mode
goto end
:die
(call)
>&2 echo(program ended unexpectedly
:end
endlocal & goto :eof
But I think if I go down this road any farther, it will lead only to madness. There are too many edge cases for a watertight solution. A much simpler alternative is to redirect a newline into a file and if the file size isn’t 2, then we’re not in ANSI anymore, Toto…
- SB