alias terminating before it should

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
#1
I have this alias I've created for testing purposes called UpUtils. Its purpose is to update several locations where I have my utilities directory stored - some on other computers, some on USB devices. (In the alias below, D, F and K are potentially USB drives, although any number of them might be connected to the computer at any given time.)

UpUtils=echo Q: %+ *copy /u /h /e /y /s C:\Utils Q:\Personal\MFerguson\Utils %+ echo D: %+ if %@ready[D:] == 1 if isdir D:\Utils *copy /u /h /e /y /s C:\Utils D:\Utils %+ echo F: %+ if %@ready[F:] == 1 if isdir
F:\Utils *copy /u /h /e /y /s C:\Utils F:\Utils %+ echo K: %+ if %@ready[K:] == 1 if isdir K:\Utils *copy /u /h /e /y /s C:\Utils K:\Utils %+ echo R: %+ if isdir R:\Utils *copy /u /h /e /y /s C:\Utils R:\Utils


I've added debugging stuff to the alias to help troubleshoot what's going on - I don't need the echo part of each command, nor would I expect to have to include the %@ready part, since I would think that isdir would cover it. But when I execute this alias, with a D: drive and a K: drive existing but no F:, I expect it to list Q:, then D:, the F:, then K: then R:. I only see Q:, D: and F:, and the actual file copy (copies) for F: doesn't even happen, and no K: or R:. It seems that when it hits the 'if isdir F:\Utils' statement, it terminates the alias completely. No error message or anything like that.

TCC 16.03.55 x64 Windows 7 [Version 6.1.7601]
TCC Build 55 Windows 7 Build 7601 Service Pack 1
 

samintz

Scott Mintz
May 20, 2008
1,228
11
Solon, OH, USA
#2
You are better off making that a BTM script and using your alias to invoke the script. The alias is evaluated all at once as a single command line statement and the IF processing doesn't have any ELSE's. So if the IF is false, it's going to stop right there.

UpUtils.btm:
Code:
gosub DoUpdate Q:\Personal\MFerguson\Utils
gosub DoUpdate D:\Utils
gosub DoUpdate F:\Utils
gosub DoUpdate K:\Utils
gosub DoUpdate R:\Utils
quit

:DoUpdate [dest]
echo %@drive[%dest]
iff %@ready[%dest] == 1 then
    if isdir %dest *copy /u /h /e /y /s C:\Utils %dest
endiff
return
 
#3
You are better off making that a BTM script and using your alias to invoke the script. The alias is evaluated all at once as a single command line statement and the IF processing doesn't have any ELSE's. So if the IF is false, it's going to stop right there.
Thanks, Scott. I didn't know the 'if' (not 'iff') statements were short-circuit. That certainly explains it.

Of course my older version of TCC doesn't have the %@drive[] function, but I can easily take it from here.
 
Jul 29, 2016
36
1
#4
It might also be because "Duplicate CMD Bugs" is turned on. CMD will end all further processing of the command line if an IF condition is found to be false, even if there are command separators after the IF command and between any following commands. Turning off "Duplicate CMD Bugs" or using IFF instead of IF would probably solve it.