This article describes how to create a user defined command that will let you run a script or a program and capture its standard output as a text file.
A version of this macro included in releases 3.00.445 and prior but its message with the timing would not be visible after running commands that load files. This one works correctly with all commands. This version will be included in the next release.
Macro Features:
Takes the rest of its command line and runs them as a WinPTE command. Combined with the Run Command will let you do rough timing of script execution time.
- Takes its command line arguments and executes them as a WinPTE command.
- Uses the system tick clock to measure elapsed execution time.
- Displays the elapsed time in ms on the status bar for the execution of the command.
- If no arguments are given will display instruction in the status bar.
- Creates a timer key definition that re-displays the message after a short delay (200ms) after the macro is done, just in case the command that was run would cause the message to be prematurely erased.
- The 'command timeit timeIt' at the bottom of the script creates a user defined command named 'timeit' and associates it with the macro named 'timeIt' that is created in this script. Command names are not case sensitive, macro names are case sensitive.
Instructions:
If the instructions are not clear then you may want to read the Quick Review on the parent page, failing that e-mail support and the instructions will be clarified.
To give it a test flight:
- Select and copy the Macro Text below to the clipboard and add it to a new file in WinPTE.
- On the command line execute the macro command.
- Now you have the TIMEIT (not case sensitive) command.
To make it available every time you run WinPTE:
- Select and copy the text below to the clipboard and add it to your custom.pte file (in the installation directory, create a new file if it does not exist)
- Restart WinPTE or execute 'macro custom.pte' command.
- You now have a RUN command
Trying it out
type 'timeit dir' and hit ENTER, you will see the elapsed time it took to run the dir command and load the contents.
You should see the directory listing loaded in a new file (same name as the batch file with a . prefixed to it).
Macro Text
Line
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
|
* File: main.pte, lines 8914 to 8934
begindef timeIt 'timeIt'
[set envir 200][command line]
[clear command]
[extract left 200]'= ' * remove the timeit command word
[extract left 200]'- ' * remove the timeit command word
[if equal]''[envir 200]
[error 0b00011101]'syntax: timeIt {any command}'[abort]
[endif]
[eval]'$201=@system.ticks'
[execute][envir 200]
[update 2]
[set envir 99][concat][eval]'@system.ticks-$201'' ms --> '&[envir 200]
[error 0b10011110][envir 99]
* just in case the command resets and hogs the error message
[execute]'def timer=[error 0b00011110][envir 99][execute]\'set timer off\'[execute]\'def timer=\''
[execute]'set timer 2'
enddef
command timeit timeIt
|