Set encoding for batch file

Aug 3, 2017
11
1
Is there a way to set the code page for a certain batch file?

I have all those old batch files from 4NT/4DOS times that are written with CP 437 and the umlauts come out wrong. Sure, I could switch to CP 850 now, but I'd rather have an option that describes what CP a batch file is in, thus allowing for good internationalisation.

Python as a blueprint come to mind: https://www.python.org/dev/peps/pep-0263/

Any other scheme will do as well... ;)
 
Aug 3, 2017
11
1
Sorry, I expressed myself badly. I don't want to change the code page of the system. I want to specify the encoding of the batch file.
 
May 20, 2008
11,437
99
Syracuse, NY, USA
CHCP doesn't change the code page of the system; it changes the code page of TCC itself (and its child processes). If TCC is reading the batch file, I suppose you want to do exactly what David said. You can get the current code page at the beginning of the batch file, and restore it at the end. For example, if TCC is normally using some other code page and the batch file wants to be interpreted by code page 850, you could
Code:
set oldcp=%@word[3,%@execstr[chcp]]
chcp 850
rem more of batch file
chcp %oldcp
quit

But you'd have to worry about the batch file exiting without restoring the code page (error, break, ...).
I don't know how often users need to run a batch file in a code page other than the current one, but two things would make it easier and more foolproof.

1. a _CP variable so one could simply "set oldcp=%_cp"

and/or

2. (better?) a way to specify/change (inside the batch file) the code page for only the duration of the batch file, perhaps "BATCHCP 850", so TCC would revert to the old code page automatically when the batch file exits (for any reason).

Maybe a simple solution would be to make SETLOCAL/ENDLOCAL save/restore the current code page.
 
Similar threads
Thread starter Title Forum Replies Date
V Set path permanently from within TCC? Support 3
S Debugger keeps breaking with no break point set. Support 1
Joe Caverly Set a batch variable (%1 - %n) when TCC is executing a batch file Support 5
R How to? Set default application in a special folder Support 4
A How to? Set up SMTP password in TCC-RT Support 1
vefatica WAD More SET /A woes Support 4
vefatica SET /A and multidimensional array. Support 1
M How to set Path variable for non-executable file extensions in 4DOS Support 8
D Need to set Take Command font size when switching to high DPI display Support 0
P "Set" command behavior - a bug? Support 3
M How to? Set the ribbon titles to mixed case Support 1
X How to set %_INIREAD result to variable Support 5
M WAD Set statements in () causes problems Support 8
M How to? How to set a default TITLE for newly opened tab? Support 2
M Fixed Set "VAR=VAL" format causes problems Support 12
vefatica SET /A var=expression=digits Support 3
B TCC 21.01.50 Problem with ALIAS /r and SET /r Support 2
vefatica SET /A var\=...? Support 10
dcantor Documentation SET /T: missing from heading Support 0
fpefpe Documentation Set /v Support 4
vefatica What's SET /Z? Support 1
R Fixed set /r has stopped working in build 35 Support 4
BeechComer Debugger: how to set %1 variable? Support 3
fpefpe How to? Global variable set /v Support 4
fpefpe Documentation Can the title line of tcmd be set? Support 4
J How to set working directory Support 10
Jay Sage Failure of ACTIVATE to Set a Window Position Support 3
rps Fixed Win "set /p" not working in V17 build 53 Support 3
vefatica SET /A "var%=N", TCC vs. CMD Support 0
J Set environment variable from stdout of command Support 3
B How to? Pre-set _tcfolder on startup when Folders is set Auto-Hide Support 6
Dan Glynhampton Fixed @version "force" flag not working, and unable to set separator Support 3
R WAD /= size ranges not set correctly Support 5
S How to? Set the timestamp of ZIP command built archive to match latest member Support 8
Mordachai Help! How to set parameters for script I'm debugging?! Support 6
Roedy SET= Support 2
A How to? Set up a log file for all command output Support 3
M Fixed character set in dir/copy Support 3
Phileosophos Fixed TakeCommand exits upon "set [" command Support 14
R How to set comspec to point to cmd.exe? Support 5
S WAD SET problem - array element initialization Support 11
C Wildcard expansion in FOR set Support 27
vefatica SET question Support 16
T Set 1% then Echo 1% Support 9
S SET /A question; HELP nits Support 8
noahcoad copy /w to FTP does not set time stamp Support 1
M A request for a new feature for the "set" command... Support 5
cgunhouse Accessing variables set using SET /U or SET /S Support 3
D Force For to treat set of values as text, not files Support 3
vefatica Regular expressions in FOR's set? Support 10

Similar threads