tauro

01.03.2025, 04:19 |
BATCH script to save DATE to a variable (Users) |
@echo off
echo @echo off> current.bat
echo set date_=%%4>> current.bat
echo. | date | find.exe "Current" > go.bat
call go
if exist current.bat del current.bat
if exist go.bat del go.bat
I wrote this script after reading some of Timo Salmi's FAQs.
This saves the current date to the variable date_ so it can be used later.
But there's a few key things that I don't understand.
I discovered that the name of the first script "current.bat" must coincide with the term used with find.exe.
Otherwise the script doesn't work. Why is this so?
Why calling "go.bat" is correct? As far as I can understand that file is not supposed to be run, it's data to feed current.bat so that it can extract the desired field, %4, i.e. MM-DD-YYYY.
When does current.bat run and how does it get the information from go.bat?
What's trick here?
I'm open to all your suggestions and corrections. I'm here to learn.
|
Rugxulo

Usono, 01.03.2025, 08:14
@ tauro
|
BATCH script to save DATE to a variable |
> I wrote this script after reading some of Timo Salmi's FAQs.
I appreciate the minimalist approach, but perhaps a simple debug script or assembly tool would be cleaner. (Or even using REXX or 4DOS.)
> This saves the current date to the variable date_ so it can be used later.
Many DOS shells already provide this. What particular environment(s) are you targeting?
> But there's a few key things that I don't understand.
>
> I discovered that the name of the first script "current.bat" must coincide
> with the term used with find.exe.
> Otherwise the script doesn't work. Why is this so?
The line starts with "Current", so when GO.BAT is run, it runs that.
> I'm open to all your suggestions and corrections. I'm here to learn.
I would suggest using a FOR command to shorten these two lines into one:
> if exist current.bat del current.bat
> if exist go.bat del go.bat
for %%a in (current go) do if exist %%a.bat del %%a.bat |
ecm

Düsseldorf, Germany, 01.03.2025, 12:15
@ Rugxulo
|
BATCH script to save DATE to a variable |
> > I wrote this script after reading some of Timo Salmi's FAQs.
>
> I appreciate the minimalist approach, but perhaps a simple debug script or
> assembly tool would be cleaner. (Or even using REXX or 4DOS.)
>
> > This saves the current date to the variable date_ so it can be used
> later.
>
> Many DOS shells already provide this. What particular environment(s) are
> you targeting?
There's a problem with translating this to assembly language: Finding and writing to the correct parent process's environment block is a hurdle. --- l |
marcov
01.03.2025, 12:45
@ Rugxulo
|
BATCH script to save DATE to a variable |
> > I wrote this script after reading some of Timo Salmi's FAQs.
>
> I appreciate the minimalist approach, but perhaps a simple debug script or
> assembly tool would be cleaner. (Or even using REXX or 4DOS.)
(actually this was one of my motivations to go to 4dos in the mid nineties. Running multiple dosboxes in Desqview could cause clashes if the same command that spawned files was run in multiple boxes and generated files) |
Rugxulo

Usono, 01.03.2025, 18:43
@ tauro
|
BATCH script to save DATE to a variable |
D.BAT
@echo off
if not exist %0 %0.bat
debug < %0
goto end
n d.com
rcx
a3
a 100
mov di,1a3
push di
call 10e
pop dx
mov ah,9
int 21
int 20
mov si,16a
mov ah,2a
int 21
xor ah,ah
mov bx,cx
add si,ax
add si,ax
add si,ax
movsw
movsb
mov al,20
stosb
mov al,dh
xor ah,ah
dec ax
mov si,17f
add si,ax
add si,ax
add si,ax
movsw
movsb
mov al,20
stosb
mov al,dl
mov cx,a
aam
xchg al,ah
or ax,3030
stosw
mov al,2c
stosb
mov ax,bx
mov bx,4
xor dx,dx
jmp short 152
xchg bx,cx
div cx
xchg ax,dx
or al,30
push ax
xor ax,ax
xchg ax,dx
xchg bx,cx
loop 150
mov cx,4
pop ax
stosb
loop 162
mov byte ptr [di],24
ret
db "SunMonTueWedThuFriSat"
db "JanFebMarAprMayJunJulAugSepOctNovDec"
w
q
:end
D2.BAT
@echo off
if not exist %0 %0.bat
debug < %0
goto end
n d.com
rcx
a3
e 100 BF A3 01 57 E8 07 00 5A B4 09 CD 21 CD 20 BE 6A
e 110 01 B4 2A CD 21 30 E4 89 CB 01 C6 01 C6 01 C6 A5
e 120 A4 B0 20 AA 88 F0 30 E4 48 BE 7F 01 01 C6 01 C6
e 130 01 C6 A5 A4 B0 20 AA 88 D0 B9 0A 00 D4 0A 86 E0
e 140 0D 30 30 AB B0 2C AA 89 D8 BB 04 00 31 D2 EB 02
e 150 87 CB F7 F1 92 0C 30 50 31 C0 92 87 CB E2 F1 B9
e 160 04 00 58 AA E2 FC C6 05 24 C3
a 16a
db "SunMonTueWedThuFriSat"
db "JanFebMarAprMayJunJulAugSepOctNovDec"
w
q
:end
D.ASM
; public domain
cpu 8086
org 100h
Komenco:
mov di,printthis
push di
call date
pop dx
mov ah,9
int 21h
Fino:
int 20h
date:
mov si,days
mov ah,2Ah
int 21h
.day_of_week:
xor ah,ah
mov bx,cx
add si,ax
add si,ax
add si,ax
movsw
movsb
mov al,' '
stosb
.month:
mov al,dh
xor ah,ah
dec ax
mov si,months
add si,ax
add si,ax
add si,ax
movsw
movsb
mov al,' '
stosb
.day_of_month:
mov al,dl
mov cx,10
aam
xchg ah,al
or ax,'00'
stosw
mov al,','
stosb
.year:
mov ax,bx
mov bx,4
xor dx,dx
jmp short .skip
.year_digit:
xchg cx,bx
.skip:
div cx
xchg ax,dx
or al,'0'
push ax
xor ax,ax
xchg ax,dx
xchg cx,bx
loop .year_digit
mov cx,4
.year_store:
pop ax
stosb
loop .year_store
mov byte [di],'$'
.ret:
ret
days db 'SunMonTueWedThuFriSat'
months db 'JanFebMarAprMayJunJulAugSepOctNovDec'
section .bss align=1
printthis resb 16
--- Know your limits.h |
tauro

02.03.2025, 02:16
@ Rugxulo
|
BATCH script to save DATE to a variable |
> The line starts with "Current", so when GO.BAT is run, it runs that.
Thank you!
That's so obvious, how didn't I notice it?
> I would suggest using a FOR command to shorten these two lines into one:
> for %%a in (current go) do if exist %%a.bat del %%a.bat
Thanks for this!
> 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.
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.
> I appreciate the minimalist approach, but perhaps a simple debug script or assembly tool would be cleaner. (Or even using REXX or 4DOS.)
Using assembly is probably a better way to do this, I agree. But it's out of my capabilities (at least for now). So your code is nothing short of black magic for me.
I compiled it and it prints the date this way:
Sat Mar 01,2025
But it doesn't create the DATE_ variable.
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.
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.
If you can recommend any reading material on assembly for beginners that'd be great. |
Rugxulo

Usono, 02.03.2025, 03:26
@ tauro
|
BATCH script to save DATE to a variable |
> > 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 |
rosegondon
C:\DOS, 02.03.2025, 17:10
@ tauro
|
BATCH script to save DATE to a variable |
If you have access to Pascal compiler and you are willing to rely on external tool, you can store up to 16 bytes in
memory area known as ICA or IPCA (Inter-Process Communication Area):
Procedure IPCA(Const Get : Boolean; Var SourceDest; Const Size:Integer);
Begin { IPCA }
If Get Then
Move(Mem[$0000:$04F0],SourceDest,Min(16,Size))
Else
Move(SourceDest,Mem[$0000:$04F0],Min(16,Size));
End; { IPCA } --- echo g=ffff:0|debug>nul |
RayeR

CZ, 25.03.2025, 05:44
@ tauro
|
BATCH script to save DATE to a variable |
> 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.
What version do you use? The latest is 0.60.45 released 2010-09-09
http://www.navsoft.cz/produkty.htm
seems to be outdated a long time ago. It's a pity insertion of timebomb, even in freeware (message can be skipped but it's bugging). It would deserve a cr... but EXE seems to be packed/encrypted some way and it checks integrity at startup so faking the current date is easier... --- DOS gives me freedom to unlimited HW access. |
rr

Berlin, Germany, 25.03.2025, 18:41
@ tauro
|
BATCH script to save DATE to a variable |
> 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.
What NSSI version are you using? Latest 0.60.45 is from 2010 and has no problems with that year.
> 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.
A quick hack:
1) Grab the FAKEDATE TSR program from https://soulsphere.org/mirrors/www.rome.ro/lee_killough/versions/prnotes.shtml
2) Unpack fakedate.zip
3) Use your favorite binary/hex editor and load FAKEDATE.COM
4) At offset 0Bh turn C9 into DA. This will give you 10-OCT-2010.
5) Save the file and quit the editor
6) Run FAKEDATE.COM to load the TSR
7) Run NSSI.EXE
8) Run FAKEDATE.COM /U to unload
Source code is at: https://github.com/fragglet/mbf/blob/master/fakedate.asm --- Forum admin |