[comp.sys.ibm.pc] MS-DOS Environment Variables

mhampson@wpi.wpi.edu (Mark A. Hampson) (11/17/89)

I am wondering if anyone has tripped across a way to set an MS-DOS
environment variable from within a program that is still in the 
environment table when the program terminates.

The commands in Turbo * will allow you to alter the environment 
variable table, but when they only operate on a copy of the table
which is created when you execute the program and therefore are lost
on termination.

I am trying to store the current directory path name in an environment
variable.  I am willing to approach this two ways:

1)  have a program return the value in such a way that a .BAT file 
    can set it and have it stay in the table 

2)  or to have a program set it (the prefered method).


If anyone has any great ideas on this could you please EMAIL them to me
as I do not read this newsgroup regularly.

Thanks,
-- 
/----------------------------------------------------------------------------\
|      We are not in an energy crisis, we are having an entropy crisis...    |
\----------------------------------------------------------------------------/
                  Mark A. Hampson  --  mhampson@wpi.wpi.edu

ts@uwasa.fi (Timo Salmi LASK) (11/21/89)

In article <5679@wpi.wpi.edu> mhampson@wpi.wpi.edu (Mark A. Hampson) writes:
>I am wondering if anyone has tripped across a way to set an MS-DOS
>environment variable from within a program that is still in the 
>environment table when the program terminates.
>
>I am trying to store the current directory path name in an environment
>variable.  I am willing to approach this two ways:

I have solved this very problem in my non-resident pushdir / popdir
batches.  You can obtain them by anonymous ftp from our site.  They
are part of my /pc/ts/tsbat12.arc package. 

>If anyone has any great ideas on this could you please EMAIL them to me
>as I do not read this newsgroup regularly.

Sorry, no.  I prefer to post, since there always may be others who
might be interested in the same problem.  (No offence meant, but I
have often wondered about these offhand postings, where the person
doing the posting is not interested enough to follow things trough.)

...................................................................
Prof. Timo Salmi                                (Site 128.214.12.3)
School of Business Studies, University of Vaasa, SF-65101, Finland
Internet: ts@chyde.uwasa.fi Funet: vakk::salmi Bitnet: salmi@finfun

thorp@spudge.UUCP (Don Thorp) (11/21/89)

The following code will set an environment variable in the highest 
environment.  I compiled it with tasm and zortech cpp.  But there should
be no changes required for MSC or TurboC.  The transient portion of
command.com will be loaded.  If there is not enough memory to load 
command.com, your system will crash.  That is one of the side effects of 
using interrupt 2Eh.

Don Thorp
USENET ...!texbell!letni!rwsys!spudge!thorp

<------------------------------Cut Here----------------------------------->
/**********************************************************************
 * setenv.h
 *
 **********************************************************************/

#if !defined(__SETENV_H__)

#define __SETENV_H__

#if defined(__cplusplus)
extern "C" {
#endif

void int2e(char *cmd);
void setenv(const char *p);

#if defined(__cplusplus)
}
#endif

#endif
<------------------------------Cut Here----------------------------------->
/*************************************************************************
 * setenv.c - Set the root environment
 *
 ************************************************************************/

#include <stdlib.h>
#include <string.h>

#include "setenv.h"

void setenv(const char *p) {

  char *cmd = malloc(strlen(p) + 3);

  cmd[0]=strlen(p);
  strcpy(cmd+1,p);
  strcat(cmd+1,"\r");

  int2e(cmd);

  free(cmd);
}
<------------------------------Cut Here----------------------------------->
;  Interrupt 2Eh Call for C  int2e.asm
;
;  void _int2e(char *cmd)
;
                Public _int2e
_TEXT           Segment Byte Public 'CODE'
                Assume CS:_TEXT

Stack           dw      ?,?

_INT2E          proc    near
                push    bp
                mov     bp,sp
                push    si                      ;Save registers
                push    di
                push    ds
                mov     cs:[Stack], sp          ;Save the stack pointer
                mov     cs:[Stack+2], ss
                mov     si, ss:[bp+4]           ;Get parameter

                int     2eh                     ;do interrupt

                mov     ss, cs:[Stack + 2]      ;restore stack
                mov     sp, cs:[Stack]
                pop     ds
                pop     di
                pop     si
                pop     bp
                ret
_INT2E          endp
_TEXT           ends
                end

las) (11/22/89)

In article <5679@wpi.wpi.edu> mhampson@wpi.wpi.edu (Mark A. Hampson) writes:
>I am wondering if anyone has tripped across a way to set an MS-DOS
>environment variable from within a program that is still in the 
>environment table when the program terminates.

Watch for my forthcoming post of my "bios-only" version of STEVIE in 
comp.binaries.ibm.pc (assuming Rahul accepts it).  In it will be
included a SETENV program (with Turbo C source) which can do this.  
SETENV is based on an earlier posting to cbip by Alan J. Myrvold.

regards, Larry
-- 
Signed: Larry A. Shurr (cbema!las@att.ATT.COM or att!cbema!las)
Clever signature, Wonderful wit, Outdo the others, Be a big hit! - Burma Shave
(With apologies to the real thing.  The above represents my views only.)
(Please note my mailing address.  Mail sent directly to cbnews doesn't make it.)

tim@stiatl.UUCP (Tim Porter) (11/23/89)

In article <1989Nov20.212803.5326@uwasa.fi> ts@chyde.uwasa.fi (Timo Salmi LASK) writes:
>I have solved this very problem in my non-resident pushdir / popdir
>batches.  You can obtain them by anonymous ftp from our site.  They
>are part of my /pc/ts/tsbat12.arc package. 
>
 
This sounds just like what I've been looking for!  But, I unfortunately do
not have anonymous ftp access.  Could anyone who does be so kind as to email
me a copy?  I would be forever grateful.

tim@stiatl.UUCP (Tim Porter) (11/30/89)

In article <6551@spudge.UUCP> thorp@spudge.UUCP (Don Thorp) writes:
>The following code will set an environment variable in the highest 
>environment.  I compiled it with tasm and zortech cpp.  But there should
>be no changes required for MSC or TurboC.  The transient portion of
>command.com will be loaded.  If there is not enough memory to load 
>command.com, your system will crash.  That is one of the side effects of 
>using interrupt 2Eh.
>
>

Thanks a million.  This IS exactly what I needed and it's working 
wonderfully!

But I do have one question.  Do you know if the use of this interrupt 
(2EH) is portable across different versions of DOS?  If it is, this
could be even better news than what I had initially hoped for.


					    Tim "THE GREATful" Porter 
-- 
*******************************************************************************
|  Tim Porter                             gatech!stiatl!tim                   | 
|  Sales Technologies, Inc    Atlanta, GA  (404) 841-4000                     | 
*******************************************************************************