1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Equivalent of PRE_EXEC/POST_EXEC in a batch file

Discussion in 'Support' started by p.f.moore, Jul 4, 2008.

  1. p.f.moore

    Joined:
    May 30, 2008
    Messages:
    122
    Likes Received:
    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. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    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
     
  3. p.f.moore

    Joined:
    May 30, 2008
    Messages:
    122
    Likes Received:
    1
    2008/7/5 Steve Fábián <>:

    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:


    hello
    Elapsed: 0.01s

    ... 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.
     

Share This Page