- May
- 13,604
- 201
[A bit of smoke and mirrors here!]
When you load functions with
Notes:
- I believe the rules are line-continuation removes the newline and leading whitespace on the next line
- Anything inside %@exec[@ ...] is executed and the '@' suppresses @EXEC's return value (it returns an empty string).
- @EXEC is probably limited by the command line length limit (which is at worst huge, and today, perhaps, equal to available memory).
- I threw in the ECHOs (with redirection and piping) and the DO only to show that any (so far) one-line command can be used in @EXEC.
- You probably wouldn't want something in @EXEC to produce output.
- In memory, the function winds up on one line.
When you load functions with
FUNCTION /R
line continuations (^) are respected. This lets you (at least in a sense) define multi-line UDFs (example far below).Notes:
- I believe the rules are line-continuation removes the newline and leading whitespace on the next line
- Anything inside %@exec[@ ...] is executed and the '@' suppresses @EXEC's return value (it returns an empty string).
- @EXEC is probably limited by the command line length limit (which is at worst huge, and today, perhaps, equal to available memory).
- I threw in the ECHOs (with redirection and piping) and the DO only to show that any (so far) one-line command can be used in @EXEC.
- You probably wouldn't want something in @EXEC to produce output.
- In memory, the function winds up on one line.
Code:
d:\tc29> type secs2dhms.fn
secs2dhms=^
%@exec[@ ^
set _x=%1 ^
& set _d=%@eval[%_x\86400] ^
& set _x=%@eval[%_x MOD 86400] ^
& set _h=%@eval[%_x\3600] ^
& set _x=%@eval[%_x MOD 3600] ^
& set _m=%@eval[%_x\60] ^
& set _x=%@eval[%_x MOD 60] ^
& echo foo > NUL ^
& echos foo | findstr bar ^
& do i=1 to 2 (echo foo > NUL) ^
]^
%_d:%@format[02,%_h]:%@format[02,%_m]:%@format[02,%_x]
d:\tc29> function /r secs2dhms.fn
d:\tc29> echo %@secs2dhms[90000]
1:01:00:00
d:\tc29> function secs2dhms
%@exec[@ set _x=%1 & set _d=%@eval[%_x\86400] & set _x=%@eval[%_x MOD 86400] & set _h=%@eval[%_x\3600] & set _x=%@eval[%_x MOD 3600] & set _m=%@eval[%_x\60] & set _x=%@eval[%_x MOD 60] & echo foo > NUL & echos foo | findstr bar & do i=1 to 2 (echo foo > NUL) ]%_d:%@format[02,%_h]:%@format[02,%_m]:%@format[02,%_x]