cmd - Set one variable in another batch file -


i set variable in batch file, if exsists. works localy in sub batch file. how can fix problem?

main.bat:

set temp="" if exist sub.bat (     call sub.bat        rem returns: temp="" in main       echo %temp% in main ) else (       set temp="default value" ) 

sub.bat:

set temp="other value" rem returns: temp="other value" in sub echo %temp% in sub 

output calling main.bat:

temp="other value" in sub temp="" in main 

two issues:

your test incorrect. within block statement (a parenthesised series of statements), entire block parsed , then executed. %var% within block replaced variable's value at time block parsed - before block executed - same thing applies for ... (block).

hence, if (something) else (somethingelse) executed using values of %variables% @ time if encountered.

try using call echo %%temp%% display altered value , "delayedexpansion" endless items on frequently-encountered subject.

second issue - impinges on first.

temp , tmp special variablenames specify location of temporary-files directory. best not change them unexpected results may ensue. use variablename.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -