Back to home page

DOS ain't dead

Forum index page

Log in | Register

Back to the forum
Board view  Mix view

BATCH script to save DATE to a variable (Users)

posted by Rugxulo Homepage, Usono, 02.03.2025, 03:26

> > Many DOS shells already provide this. What particular environment(s) are
> > you targeting?
> I mainly use DOS 7.1 and 6.22 with the standard shell. I use FreeDOS too
> but not for this.

4DOS, DR-DOS COMMAND.COM, and Win7's CMD all have date variables, IIRC.

> There's a freeware diagnostics program, NSSI, that I run on different
> computers while testing them, that is hard coded to print an error message
> if the current date is past 2008.
>
> So with my script I save the current date, set the date as 12-31-2008, run
> the program, and then set the correct date again.

Maybe you need KEEPTIME?

* https://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/util/system/keeptime/

> > KEEPTIME stores system time to time stamp of given file (and creates
> > file if it absent) or restores system time from time stamp of file
> > if file time newer than system time.

That should work simply enough.

> I compiled it and it prints the date this way:
> Sat Mar 01,2025
>
> But it doesn't create the DATE_ variable.

It was just a proof of concept. I was hoping you'd modify it to your needs.

> Could you please tweak your code so that it saves its content to the
> variable DATE_ with the date in this format MM-DD-YYYY? That's the format I
> need to use in my script to set the current date with the DATE command.

Maybe, but I'm not sure you need it.

> Is it possible to create/set a variable (the same way the SET command does)
> with an assembly program? Could you please give an example of assembly code
> that sets this environmental variable FOO=BAR? Just to try to understand it
> better.

Setting the master environment (across all processes and shells) is what is very difficult. I wouldn't recommend that.

Technically, I wouldn't even recommend directly modifying the environment memory, but at program startup, (PSP) ES:2Ch should hold a pointer to the environment data.

(Old Simtel archives have DUMPENV.ZIP to show how to read the local environment.)

The unportable, nonstandard way to set the "local" environment is this:

putenv() (DJGPP)

In short, I don't think it persists after your program ends.

> If you can recommend any reading material on assembly for beginners that'd
> be great.

Randall Hyde's old 16-bit Art of Assembly book may be online somewhere.

But you don't really need assembly here. It was just small and simple enough. Heck, just try this:

echo ? "@set date_=" ; DATE$ : SYSTEM >q.bas
qbasic /run q >q.bat
call q

 

Complete thread:

Back to the forum
Board view  Mix view
22477 Postings in 2087 Threads, 400 registered users, 132 users online (1 registered, 131 guests)
DOS ain't dead | Admin contact
RSS Feed
powered by my little forum