On Apr 13, 10:30 pm, "Liviu" <lab...@gmail.c0m> wrote:>
> The 'call' above should work, and an "echo %outvar%" right after should
> return "c:\ab\xyz\def". It does so here.
>
> Make sure your "C:\bat\replace-any-char.bat" contains just the quoted
> code, and no extra "setlocal" at the top (which would make the 'outvar'
> assignment local to the .bat).
>
> Liviu
>
> P.S. Also, you can drop the entire 'if "!errorlevel!"=="%errorlevel%"
> (...)' block from the posted code, which upon a second look is wrong,
> anyway. It doesn't really matter in your case since your echo's indicate
> a default disableDelayedExpansion run, so that block is not executed.
I made dozens -- probably > 100 -- runs trying different
configurations of the output variable and other things. I remember
using SETLOCAL once just to see what difference it would make. When it
didn't "help", I removed it from my script. I honestly don't recall
EVER using SETLOCAL ENABLEDELAYEDEXPANSION or SETLOCAL
DISABLEDELAYEDEXPANSION, but it's possible I might have tried them. In
any event, I'm certain that, if one of them had made a difference for
the better I would have noted it.
I originally used an exact copy of the posted code. When it didn't
become obvious what was going wrong, I added an occasional echo or
pause here and there. So it's possible I might have gummed something
up and made a substantive difference in the code. However, I'm certain
that I removed the extra pauses and echoes and it was still failing.
From time to time, I even completely refreshed the copy of the code I
was making changes to from the original download of the posted code.
(I had it open in my editor for read-only, so I could not have
accidentally changed the my local copy of the posted code.) Of course
it's still possible that I messed up something in the "experimental
code" where I was adding and removing pauses and echoes, etc.
After reading your reply, I reloaded your posted code and compared it
to my local "read only" copy using WinMerge and found only three
differences:
An extra whitespace character after the left paren in [ if "!
errorlevel!"=="%errorlevel%" ( ]
An extra whitespace character at the end of [ setlocal
disabledelayedexpansion ]
An extra whitespace character after the trailing " in [ endlocal
& set "%~4=%string%" ]
I don't know whether any of these could have had an impact on my
testing.
Finally, I closed the command window, which I had been using over and
over for my testing. In the fresh window, my tests no longer fail! I
even tried with each of the three SETLOCAL lines, and none of those
failed either. So I must have introduced the problem in one of the
"slight" changes I made during my testing between refreshes of the
posted code.
Thanks again, Liviu, for the code and I apologize for wasting your
time.
Phil