Equivalent of PRE_EXEC/POST_EXEC in a batch file

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
May 30, 2008
122
1
#1
I'd like to write a batch file with a bit of processing around each
command (specifically, I want to display the command plus the time it
took). At the interactive prompt, I could do this with some sort of
pre_exec and post_exec aliases, but they don't work in batch files.

I suppose I could write an alias something like

alias x=`echo %$ & timer on /Q & %$ & echo Elapsed: %@TIMER[1,s] &
timer off /Q`

but this needs to be specified explicitly and gets fiddly with
compound commands (x cmd1 & cmd2).

Is there a good equivalent of PRE_EXEC/POST_EXEC for batch files?

Paul.
 
#2
p.f.moore wrote:
| I'd like to write a batch file with a bit of processing around each
| command (specifically, I want to display the command plus the time it
| took). At the interactive prompt, I could do this with some sort of
| pre_exec and post_exec aliases, but they don't work in batch files.
|
| I suppose I could write an alias something like
|
| alias x=`echo %$ & timer on /Q & %$ & echo Elapsed: %@TIMER[1,s] &
| timer off /Q`
|
| but this needs to be specified explicitly and gets fiddly with
| compound commands (x cmd1 & cmd2).
|
| Is there a good equivalent of PRE_EXEC/POST_EXEC for batch files?

No, but look at the description of the LOG command - it can record every
command executed, even those inside batch files.
--
Steve
 
May 30, 2008
122
1
#3
2008/7/5 Steve Fábián <>:

> | Is there a good equivalent of PRE_EXEC/POST_EXEC for batch files?
>
> No, but look at the description of the LOG command - it can record every
> command executed, even those inside batch files.
Thanks, I had looked at LOG, but it *only* records the commands, not
the output of those commands. To be a bit more precise, this is the
sort of output I'm trying to achieve:


>>> echo hello
hello
Elapsed: 0.01s

>>> call build_system.bat
... lots of build output
Elapsed: 30.54s

I think I'm going to have to go with a "log & exec" type alias, as I
originally thought. Oh, well - it'll have to do.

Paul.