delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/02/03/13:27:23

From: "Robert B. Clark" <rclark AT iquest DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Setting DOS environment variables
Organization: ClarkWehyr Enterprises
Message-ID: <r9bj9sgi45s97l6scok6snnslc9fjs11v1@4ax.com>
References: <22e8c8ce DOT 39f84b4f AT usw-ex0105-040 DOT remarq DOT com> <Pine DOT SUN DOT 3 DOT 91 DOT 1000203081550 DOT 3341E-100000 AT is>
X-Newsreader: Forte Agent 1.7/32.534
MIME-Version: 1.0
Lines: 56
Date: Thu, 03 Feb 2000 11:45:43 -0500
NNTP-Posting-Host: 209.43.53.111
X-Trace: news1.iquest.net 949596355 209.43.53.111 (Thu, 03 Feb 2000 11:45:55 EDT)
NNTP-Posting-Date: Thu, 03 Feb 2000 11:45:55 EDT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Eli Zaretskii <eliz AT is DOT elta DOT co DOT il> wrote:

>On Wed, 2 Feb 2000, wriska wrote:
>
>> I am trying to set DOS environment variables from within a DJGPP
>> C program, but I am not having much success.  Would someone
>
>(Well, actually, it *is* possible to change the environment of the
>parent shell, but it involves walking the DOS memory chain, which is
>very complicated and totally unportable.)

The only "portable" way to do this is to have the executable run from
within a batch file.  Upon exit, the executable writes a second batch
file with the appropriate SET commands.  Then the original batch file
will run the auxiliary batch file.

For example:

	rem RUNFOO.BAT
	rem This batch runs FOO.EXE, which sets PROMPT=[FOO]$p$g
	rem FOO.EXE writes an auxiliary batch named in the argument list
	echo The value of PROMPT is %prompt%
	foo.exe $tmpfoo.bat
	call $tmpfoo
	echo The value of PROMPT is %prompt%

The batch file that FOO.EXE writes would look something like this:

	@set prompt=[FOO] $p$g

Finally, FOO.C looks like this:

	#include <stdio.h>
	#include <stdlib.h>

	int main(int argc, char *argv[])
	{
		FILE *fp = NULL;

		if (argc > 1)
		{
			if ((fp = fopen(argv[1], "wt")) == NULL)
				perror(argv[1]);
			else
			{
				fprintf(fp, "@set prompt=[FOO] $p$g\n");
				fprintf(fp, "@del %s\x1b", argv[1]);
				fclose(fp);
			}
		}
		return fp ? EXIT_SUCCESS : EXIT_FAILURE;
	}

-- 
Robert B. Clark
Visit ClarkWehyr Enterprises On-Line at http://www.iquest.net/~rclark/ClarkWehyr.html

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019