Back to home page

DOS ain't dead

Forum index page

Log in | Register

Back to the forum
Board view  Mix view

save & restore environment (Developers)

posted by bencollver Homepage, 28.02.2026, 00:52

I ran into a situation in SvarDOS where the EDR-DOS command interpreter was creating duplicate environment variables. For example, when i ran the SET command, i might see multiple PATH= variables in its output. I believe it was related to running out of space in the environment. The way i worked around this problem was by increasing the size of the environment, and also by running COMMAND /C instead of CALL to run helper .bat files. With COMMAND /C the original environment is restored when the helper .bat file completes.

I found myself wishing for a utility to back up and restore the environment. As an exercise, i wrote a couple of AWK scripts to do it.

mkenvset.awk

# Usage: awk -f mkenvset.awk >envset.bat
# Run envset.bat to restore all environment variables
BEGIN {
    for (k in ENVIRON) {
        printf "SET %s=%s\n", k, ENVIRON[k]
    }
}


mkenvdel.awk

# Usage: awk -f mkenvdel.awk >envdel.bat
# Run envdel.bat to delete all environment variables
BEGIN {
    for (k in ENVIRON) {
        printf "SET %s=\n", k
    }
}


I imagine using them like so:

awk -f mkenvset.awk >envset.bat
call helper.bat
awk -f mkenvdel.awk >envdel.bat
call envdel.bat
call envset.bat


This would effectively restore the original environment without using a COMMAND /C sub-shell.

What do you think? Is it a bad idea? Why?

 

Complete thread:

Back to the forum
Board view  Mix view
23247 Postings in 2191 Threads, 405 registered users (0 online)
DOS ain't dead | Admin contact
RSS Feed
powered by my little forum