On Fri, Dec 23, 2022 at 1:42 AM M. Osman Talayman <talay...@gmail.com> wrote:
>
> Hello,
>
> I just can't figure this one out: From a .bat file, I want to write
> entries to a log file. Each entry should have a date and time in the
> form YYYYMMDD:HHMMSS I have searched the internet for solutions on how
> to do this, but none of the solutions work (I think they are for
> cmd.exe in modern Windows which is more advanced than command.com).
>
> My first problem is, that I just cannot figure out how to write just
> the date without all the preceeding text (Current date is Thu
> 12-23-2022).
[..]


Why not the "Current date is" text? If you're trying to put entries
into a log file from a FreeDOS BAT file, you presumably aren't dumping
a ton of output into the log (my guess: you probably aren't writing a
ton of output to the log file, perhaps noting when a job was last run,
and probably copying the output of a command). Assuming you're just
looking to put the date and time in a log file, from a BAT file, DATE
/T and TIME /T will make a timestamp of when the command was run.

Or if you just want a program to generate the date and time, you could
do something like this:

#include <stdio.h>
#include <dos.h>

int
main()
{
  struct dosdate_t dt;
  struct dostime_t tm;

  _dos_getdate(&dt);
  _dos_gettime(&tm);

  printf("%d-%d-%d %.2d:%.2d:%.2d\n", dt.year, dt.month, dt.day,
         tm.hour, tm.minute, tm.second);

  return 0;
}



For example, if you save this as NOW.C and compile it to NOW.EXE
(using OpenWatcom C, with -ox will generate an 8k binary) you will get
output like this:

C:\> NOW
2022-12-23 17:59:54


And you can easily append that output to a file.


_______________________________________________
Freedos-user mailing list
Freedos-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-user

Reply via email to