Mail Archives: djgpp/2000/02/03/13:27:23
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 -