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 that only worked with 4NT command processor was included in releases 3.00.445 and prior. This one works correctly with cmd.exe and 4NT. This corrected version will be included in the next release.
Macro Features:
Has the effect of running a script and opening its captured output as a text file in WinPTE.
- Takes its command line arguments and passes them to cmd.exe
- Captures the output to a file with the same name as the first argument with a '.' prefixed to it.
- If no arguments are given will pass the current file name to cmd.exe. The current file should be a script file with an association for its extension to the script processor.
- The 'command run run' at the bottom of the script creates a user defined command named 'run' and associates it with the macro named 'run' that is created in this script. Command names are not case sensitive, macro names are case sensitive.
NOTE: The name starting with a . makes it a temporary file, so you will not get a prompt when you try to close it even if it is modified.
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 RUN (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
Create a simple batch file with just a "dir" command in it. Save it. Execute "run" on the command line with the batch file as the current file.
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
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
|
* File: main.pte, lines 8786 to 8825
begindef run 'run'
[set envir 209][command line]
[extract left 209]'= ' * skip leading spaces
[extract left 209]'- ' * discard the find command word, it may be incomplete
[extract left 209]'= ' * skip leading spaces
[set envir 201][extract left 209]'- ' * get the command name
[if equal]''[envir 201]
* try running the current file
[if equal][envir 241]'^*\\'[envir 241]'^d^p'
[set envir 201][envir 241]'^n^x'
[else]
[set envir 201][envir 241]'^f'
[endif]
[endif]
* 4NT can be run with this command line, it will also accept the same args as cmd.exe shell
*[set envir 200]'!dos /c "'&[envir 201]&'"'&[envir 209]&[envir 241]' >&"^$"'
* cmd.exe requires this otherwise redirection will not occur
[set envir 200]'!dos cmd.exe /c "'&[envir 201]&'"'&[envir 209]&[envir 241]' >"^$"'
[if][execute][envir 241]'delete "^$"'[endif]
[if not][execute][envir 200][error 0b00011101]'Errors while executing '&[envir 200][abort][endif]
[file wait 50][envir 241]'^$'
[execute]'edit ".'&[envir 243][envir 201]'^n^x" /nopath /new'
[bottom][data cursor]
[set envir 90][envir 241]'^$'
[push mark]
[call insertFileEnv90]
[pop mark]
[if top][else][insert line 2][down 2][endif]
[center line 101]
[down][begin line]
[error 0b00011101]
[clear command]
enddef
command run run
|