From: "Robert B. Clark" Newsgroups: comp.os.msdos.djgpp Subject: Re: Setting DOS environment variables Organization: ClarkWehyr Enterprises Message-ID: References: <22e8c8ce DOT 39f84b4f AT usw-ex0105-040 DOT remarq DOT com> X-Newsreader: Forte Agent 1.7/32.534 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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 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 #include 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