REPLVAR.BAT - regex search and replace for variables

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
carlos
Expert
Posts: 503
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

Re: REPLVAR.BAT - regex search and replace for variables

#31 Post by carlos » 10 May 2014 20:39

Liviu, thanks for the comments. Because you say that works ok. I tested again, and I found that works ok on windows 7 japanase native.

I thinked that was wrong, but, using raster font and codepage 65001, when I run 65001.bat
I get this message on windows 7 japanase:

Code: Select all

the system cannot write to the specified device


but it set correctly the variable.
If i change to codepage 932 I can see that the variable was set ok.
The error message not avoid the creation of the variable.

for avoid dude, I use:

Code: Select all

set "sokoban="
chcp 65001
65001.bat >nul
chcp 932
set sokoban
rem here i see correctly the variable.


Works ok, then dbenham can create a batch encoded as utf8 without bom for set again the variable, but this will works only on windows seven and above.

I have a idea why on windows xp japanase it set wrong or corrupted the variable.
on cmd xp
When cmd start it save a variable like cp= current, OEM_CP if not remember bad.
Then, when cmd run the batch, if you change the codepage, cmd xp use the codepage of the variable when it start for translate from multibyte to widechar, then on windows japanase, even when i do this for run the batch, using other codepage than 65000 (utf7) or 65001 (utf8):

Code: Select all

(
chcp 65001
65001.bat
chcp 932
)


at moment of run 65001.bat it not use 65001 as the codepage for multibytetowidechar, it use the codepage when cmd start, in this case 932. Because this, the variable is corrupted, because is translated using in this case codepage 932 (the codepage when cmd start), and not the current codepage 65001.

I think if is possible, change the default codepage of the system to 65001, then run cmd, change the codepage to other maybe 437, and try use the loader:

Code: Select all

(
chcp 65001
65001.bat
chcp 932
)


for verify this.
Last edited by carlos on 10 May 2014 23:39, edited 2 times in total.

Liviu
Expert
Posts: 470
Joined: 13 Jan 2012 21:24

Re: REPLVAR.BAT - regex search and replace for variables

#32 Post by Liviu » 10 May 2014 21:22

carlos wrote:using raster font and codepage 65001, when I run 65001.bat
I get this message on windows 7 japanase:

Code: Select all

the system cannot write to the specified device
Using a raster font, you'll get the exact same error on an English Windows while trying to display "‹αß©∂€›" under chcp 437 for example. That's because a raster font affects not just the glyphs being displayed, but also the internal codepage translation in the console. I've said it and repeated it, so this time I'll just let you search the board for SetConsoleOutputCP in one of your other threads (or re-read my previous reply).

As a sidenote, this is again a case where Japanese is irrelevant, yet makes it more difficult for others to check and duplicate your test cases. I don't have an Asian/CJK installation of Windows handy and, honestly, I don't have the time or dedication to set one up just for this. You'd improve your chances at getting feedback and help if you stuck to simple examples that everyone could reproduce easily.

carlos wrote:Then, when cmd run the batch, if you change the codepage, cmd xp use the codepage of the variable when it start for translate from multibyte to widechar, then on windows japanase, even when i do this for run the batch, using other codepage than 65000 (utf7) or 65001 (utf8):

Code: Select all

(
chcp 65001
65001.bat
chcp 932
)
at moment of run 65001.bat it not use 65001 as the codepage for multibytetowidechar, it use the codepage when cmd start, in this case 932. Because this, the variable is corrupted, because is translated using in this case codepage 932 (the codepage when cmd start), and not the current codepage 65001.
A few notes:
- there is no such thing as a "codepage of the variable" - variables are stored internally as UTF16 Unicode, and they don't remember what codepage they were originally defined under;
- in the case of a parenthesized construct like the above, the called commands execute in the codepage active at the time of the call, but evaluations on the calling side are done in the codepage that was active before the opening parenthesis - see http://www.dostips.com/forum/viewtopic.php?p=33543#p33543 - and this behavior hasn't changed between xp and win7;
- in win7 you don't need the parenthesis for it to work;
- in xp it doesn't work regardless of parenthesis, since batch parsing is broken under codepage 65001.

Liviu

carlos
Expert
Posts: 503
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

Re: REPLVAR.BAT - regex search and replace for variables

#33 Post by carlos » 10 May 2014 23:41

Liviu. Thanks. I was wrong with my theory. I found the problem with cmd for xp and why it crash when you run a batch using the codepage 65001 or 65000.
I will write a loader/patch for it.

Post Reply