Article View: alt.msdos.programmer
Article #1134Re: calling batch file from C prog
From: John R Buchan (jatmon)
Date: Tue, 01 Aug 1995 18:21
Date: Tue, 01 Aug 1995 18:21
65 lines
3958 bytes
3958 bytes
In article <DCM7sz.EA1@icis.on.ca>, ht108@newshost.hometown.on.ca says...
>
>Dale Nurden (dalen@goofy.iaccess.za) wrote:
>: In article <3q0107$j4p@news.iag.net>,
>: jatmon@mail.iag.net (John R Buchan (jatmon)) wrote:
>: > In article <D93H3A.tv@bashful.demon.co.uk>, root@bashful.demon.co.uk says...
>: > >Im trying to call a batch file from the end of a C program, using either
>: > >system, spawn?? or exec?? , and my problem is that although the batch file
>: > >runs, it is given a copy of the parents environment, that is much smaller
>: > >than it should be, and I am unable to ut any new environment variable in.
>: > >
>: > >Is the a way to force the batch file to be given the original environment,
>: > >rather than a copy of it ???
>: >
>: > You could always call your program from a batch file and have the batch
>: > file you want to run after the program as the next line.
>: >
>: > c:>copy con prog.bat
>: > prog.exe
>: > next.bat^Z
>
>: It depends on what exactly he was having trouble with. This is certainly an
>: option, but my guess is that he wants to be able to run a batch file and be
>: able to set new environment variables, but then return to the original
>: program afterwards. If this *is* what he wanted, then there is a solution.
>: Say your environment is 1024 bytes long (set with COMMAND /E:1024) and of
>: that 800 bytes is used (224 bytes free). The problem is that when you run
>: the batch file with system() or whatever, the new instance of COMMAND.COM
>: doesn't get the /E:1024 parameter (because system() doesn't specify it), so
>: DOS assume you want the default 160 bytes. But because 800 are already in
>: use, you get all 800 bytes without any extras. The result, you don't have
>: those extra 224 bytes.
>
>: The solution I use is a small TSR program I got from someone in this group
>: (I can't remember who offhand - it's in the docs - sorry!) which basically
>: fixes the problem. Don't ask how, it just does. I'll mail/post it if you
>: like - I have the authors permission to do so.
>
?? If you use system to launch a batch (program, or command), and from within
that batch you change an environment variable, you are only changing the copy
of the environment that was passed to that batch, when it started. You have
not altered the environment of the parent (lanching) program nor the master
environment. As soon as the batch terminates, its shell and all changes made
to it disappear.
If the poster wished to change the environment of the parent program, he could
probably find an extension provided by his compiler (ie, Borland: putenv). He
wouldn't even need to resort to a system call for this.
If he wanted to change a parent environment (ie, the parent of his program or
the base DOS shell), my suggestion is a simple solution, though arguably not
the fastest. I gather that there is also a way to access the environment of
a parent shell, but I don't play in DOS intricacies enough to know it off hand.
As for the size of the environment of the batch file (if he needs to use
system to launch one), why not just call command.com from system and specify
the environment size and the batch file in the call.
system("command /e:1024 /c mybatch.bat");
--
John R Buchan -:|:- Looking for that elusive FAQ? ftp to:
jatmon@mail.iag.net -:|:- rtfm.mit.edu /pub/usenet-by-group/....
Technical Details
Message-ID:
<3vlrbk$gv7@news.iag.net>Path:
arc1-ca.pugleaf.net!news.iag.net!usenetReferences:
<D93H3A.tv@bashful.demon.co.uk> <3q0107$j4p@news.iag.net> <etznlG0d8L2I075yn@goofy.iaccess.za> <DCM7sz.EA1@icis.on.ca>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.iag.net!usenet From: jatmon@iag.net (John R Buchan (jatmon)) Newsgroups: alt.msdos.programmer,comp.os.msdos.programmer,comp.lang.c Subject: Re: calling batch file from C prog Date: 1 Aug 1995 18:21:40 GMT Organization: Internet Access Group, Orlando, Florida Message-ID: <3vlrbk$gv7@news.iag.net> References: <D93H3A.tv@bashful.demon.co.uk> <3q0107$j4p@news.iag.net> <etznlG0d8L2I075yn@goofy.iaccess.za> <DCM7sz.EA1@icis.on.ca> NNTP-Posting-Host: pm1-orl16.iag.net X-Newsreader: WinVN 0.99.2