Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!rutgers!apple!voder!pyramid!prls!philabs!micomvax!ray From: ray@micomvax.UUCP (Ray Dunn) Newsgroups: comp.sys.ibm.pc Subject: Re: Interactive BAT files: here's how Summary: A real solution Message-ID: <1341@micomvax.UUCP> Date: 25 Oct 88 22:03:36 GMT References: <8810040015.AA21729@decwrl.dec.com> Reply-To: ray@micomvax.UUCP (Ray Dunn) Organization: Philips Electronics Ltd. (TDS - Montreal) St. Laurent QC, Canada Lines: 61 I recently gave myself a red face by pontificating on how you should use putenv to set interactively given values to environment variables from inside a 'C' program. It was correctly pointed out that this only affects a *copy* of the variables. I promised a solution, so... after putting up real money within my group as a challenge, Eric Anderson (anderson@micomvax) who otherwise is usually very usefully employed, came up with the following solution (:-). He is the proud winner of exactly $2.10 (dont ask). The batch file (any suitable name): if "%1"=="runbatch" goto runbatch getinput setinput %0 rem The name of this file (%0) is passed to setinp so can be re-executed rem Control does not return here from the batchfile setinput :runbatch rem Here you put the "real" commands you want the batch file to run rem including the use of the environment variables defined in the rem getinput/setinput mechanism The 'C' program, getinp.exe, interacts with the user and generates the file setinput.bat, which should be in the form: set var1=required value set var2=required value etc %1 runbatch The set statements should reflect the user's responses as required. The last line calls the first batch file again, with parameter runbatch. The code of getinp is very application specific, is simple, and is left as an exercise for the reader. The mechanism should be self-evident, and has the effect of running the batch commands at the :runbatch label after the environment variables are interactively defined. With this basic mechanism understood, many variations and expansions can be envisaged, one of which could be passing a question-string and a response environment variable name to getinput etc. Excrutiating contortions involving multiple calls of getinput with different "runbatch" labels are possible! All donations to reimburse the $2.10 gladly accepted! The mechanism shall be known as the Anderson Kludge. Now the only question is, does Eric deserve promotion or should he be condemned to eternally generating increasingly more and more obscure MS-DOS batch files!!! -- Ray Dunn. | UUCP: ..!philabs!micomvax!ray Philips Electronics Ltd. | TEL : (514) 744-8200 Ext: 2347 600 Dr Frederik Philips Blvd | FAX : (514) 744-6455 St Laurent. Quebec. H4M 2S9 | TLX : 05-824090