Board index » delphi » DOS Environment Access

DOS Environment Access

hi,

I need 3 vars named YEAR, MONTH and DAY in the DOS environment,for use in
.bat script.
so, due to 'stupid' limitation of date.exe i decided to write a small
exec in pascal for that.
I use function
Exec(GetEnv('COMSPEC'),'/C set YEAR =  '+MyYear);
no problem (DosErrot=0), but when i made a 'set' after my exec, nothing
appears in the dos shell.
Even with a Exec(GetEnv('COMSPEC','/C set); just after in the
same program, the output has nothing new about var YEAR.
Where is the problem ? security/provilege related (about accessing
provate DOS memory area) ? or simply a bad way for doing that ?

thanks

Frederic Beuserie

DSI / 3suisses Belgique
F.Beuse...@stbrice.be

 

Re:DOS Environment Access


Quote
Frederic Beuserie wrote:

> I need 3 vars named YEAR, MONTH and DAY in the DOS environment,for use in
> .bat script.
> so, due to 'stupid' limitation of date.exe i decided to write a small
> exec in pascal for that.
> I use function
> Exec(GetEnv('COMSPEC'),'/C set YEAR =  '+MyYear);
> no problem (DosErrot=0), but when i made a 'set' after my exec, nothing
> appears in the dos shell.
> Even with a Exec(GetEnv('COMSPEC','/C set); just after in the
> same program, the output has nothing new about var YEAR.
> Where is the problem ? security/provilege related (about accessing
> provate DOS memory area) ? or simply a bad way for doing that ?

This is well known with DOS. You can do it with a complicated
procedure, look at Pedt Scragg's homepage (you find his URL in the
clpb Mini FAQ above).

I suggest that you do it more simple: Let your program create a
.BAT file and execute it from outside.

SETDATE.BAT:
-----------
@echo off
batwrite.exe
call newbat.bat
-------------
where batwrite.exe creates the textfile NEWBAT.BAT with the desired
SET commands.

You invoke: C>setdate
--
Franz Glaser, Glasau 3, A-4191 Vorderweissenbach Austria +43-7219-7035-0
Muehlviertler Elektronik Glaser.  Industrial control and instrumentation
http://members.eunet.at/meg-glaser/           mailto:meg-gla...@eunet.at
http://www.geocities.com/~franzglaser/ http://members.xoom.com/f_glaser/

Re:DOS Environment Access


JRS:  In article <7nh2fp$lj...@news3.Belgium.EU.net> of Mon, 26 Jul 1999
09:36:48 in news:comp.lang.pascal.borland, Frederic Beuserie

Quote
<F.Beuse...@stbrice.be> wrote:
>I need 3 vars named YEAR, MONTH and DAY in the DOS environment,for use in
>.bat script.
>so, due to 'stupid' limitation of date.exe i decided to write a small
>exec in pascal for that.
>I use function
>Exec(GetEnv('COMSPEC'),'/C set YEAR =  '+MyYear);
>no problem (DosErrot=0), but when i made a 'set' after my exec, nothing
>appears in the dos shell.
>Even with a Exec(GetEnv('COMSPEC','/C set); just after in the
>same program, the output has nothing new about var YEAR.
>Where is the problem ? security/provilege related (about accessing
>provate DOS memory area) ? or simply a bad way for doing that ?

Those who post such questions in lieu of reading Timo's FAQ are on very
shaky ground when describing something as "stupid".  Item #30 refers.

However, in this case, assuming Year, Month, Day can be fixed-length
fields, there is another fairly simple answer.  With a batch-file, pre-
load the Environment with year=yyyy month=mmm, day=dd; and then make
your program seek its parent environment and replace the characters of
those strings.  Complications are avoided by not changing the length.

My   http://www.merlyn.demon.co.uk/programs/path-fix.pas   does such a
replacement, though only of a single character.

--
 ? John Stockton, Surrey, UK.  j...@merlyn.demon.co.uk   Turnpike v4.00   MIME. ?
  Web <URL: http://www.merlyn.demon.co.uk/> TP/BP/D/&c. FAQqish topics & links.
  Timo's TurboPascal <A HREF="ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip">FAQ</A>.
  <A HREF="http://www.merlyn.demon.co.uk/clpb-faq.txt">Mini-FAQ</A> of c.l.p.b.

Re:DOS Environment Access


In article <s+0VywAuNLn3E...@merlyn.demon.co.uk>,
Dr John Stockton  <j...@merlyn.demon.co.uk> wrote:
:JRS:  In article <7nh2fp$lj...@news3.Belgium.EU.net> of Mon, 26 Jul 1999
:09:36:48 in news:comp.lang.pascal.borland, Frederic Beuserie
Quote
:<F.Beuse...@stbrice.be> wrote:

:>I need 3 vars named YEAR, MONTH and DAY in the DOS environment,for use in
:>.bat script.
:>so, due to 'stupid' limitation of date.exe i decided to write a small

:Those who post such questions in lieu of reading Timo's FAQ are on very
:shaky ground when describing something as "stupid".  Item #30 refers.

Thanks, John. In this particular case I would also put forward

 34) Enticing the current date into an environment variable
 59) How get today's date into a six-character environment variable?

 161979 Mar 14 1999 ftp://garbo.uwasa.fi/pc/ts/tsbat58.zip
 tsbat58.zip A collection of useful batch files and tricks, T.Salmi

There in nothing wrong with writing a dedicated TP program, but this
problem can be solved with a batch-only method, as well.

   All the best, Timo

--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance  ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/>  ; FIN-65101,  Finland
Digital photos collection at http://www.uwasa.fi/ktt/lasktoim/photo/

Other Threads