TIMER command

#1
The help says (with the word "to" missing)
Code:
You can optionally specify a command for TIMER run. This is the equivalent of "timer on & command & timer off".
It's not quite that simple. If the command contains a pipe or redirection, then TIMER's output is piped or redirected, even if a command group is used.
Code:
v:\> timer ( echo foo > foo.txt )
 
v:\> type foo.txt
Timer 1 on: 12:17:15
foo
Timer 1 off: 12:17:15  Elapsed: 0:00:00.00
And it would seem that the handling of a command group after TIMER leaves something to be desired.
Code:
v:\> ( echo foo | grep foo )
foo
 
v:\> timer ( echo foo | grep foo )
grep: error: Cannot read file )
^C
Backticks help.
Code:
v:\> timer `echo foo > foo.txt`
Timer 1 on: 12:28:04
Timer 1 off: 12:28:04  Elapsed: 0:00:00.00
 
v:\> type foo.txt
foo
If that's the way it should be then the help should make it utterly clear.
 

rconn

Administrator
Staff member
May 14, 2008
10,415
95
#2
It's not quite that simple. If the command contains a pipe or redirection, then TIMER's output is piped or redirected, even if a command group is used.
That's not a command group; that's an argument to a command that happens to include some meaningless parentheses and output redirection. If you want to have it treated like a command group, you have to protect the entire argument string with back quotes.

Only the conditional commands (DO, IF, IFF, and FOR) accept trailing command group arguments.
 
#3
That's not a command group; that's an argument to a command that happens to include some meaningless parentheses and output redirection. If you want to have it treated like a command group, you have to protect the entire argument string with back quotes.

Only the conditional commands (DO, IF, IFF, and FOR) accept trailing command group arguments.
OK. I was expecting it to work like DO.
I don't **need** a command group. I only wanted the redirection/pipe to work correctly. That can be done by escaping the redirection/pipe character.