Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Setting env variables in conditionals

6 views
Skip to first unread message

Modur

unread,
Jun 27, 2004, 11:03:14 PM6/27/04
to
Is there a problem in setting an environment variable in a complex if ... then
clause? In the following example, observe the env variable OUTPUT_FILE.
It gets initialized to coor-diag. If OUTPUT_MODE (set in calling environ-
ment) is set to anything other than PDF, that value gets appended to
OUTPUT_FILE through the first SET statement in the if ... then clause.
So, if OUTPUT_MODE is COPY, OUTPUT_FILE should be set to coor-diag.COPY
through that statement.

set OUTPUT_FILE=coor-diag
...
if not %OUTPUT_MODE%==PDF (
set OUTPUT_FILE=%OUTPUT_FILE%.%OUTPUT_MODE%
echo %OUTPUT_FILE%
...
if exist ... (if exist ... (
...))) else (
if ... (if exist ... (if exist ... (
...)))
)

In fact, when OUTPUT_MODE is COPY, the echo statement shows OUTPUT_FILE
is still set to coor-diag, not coor-diag.COPY as one would expect. But
a "SET" command on the DOS shell shows the correct value for OUTPUT_FILE.

Does any one have an explanation for this?

Thanks

Charles Dye

unread,
Jun 28, 2004, 8:23:02 AM6/28/04
to

I don't believe that you are using MS-DOS, or a DOS shell. This looks
more like the Windows 2000/XP shell CMD.EXE to me. You would be better
served by a group devoted to that environment, like alt.msdos.batch.nt
or microsoft.public.win2000.cmdprompt.admin.

Personally I try to avoid Microsoft's primitive command shells as much
as possible, both in DOS and in their other operating systems. But I
suspect that this is one of those situations where you need to use
CMD.EXE's clumsy 'delayed expansion' feature. How you make it work in
multiply-nested IF statements like that is something I can't help you
with; sorry.

--
Charles Dye ras...@highfiber.com

0 new messages