guard
December 11th 03, 09:28 PM
The "Redir Rapids" Series of .Mount/\Commands provides several methods to
(re)direct the output of any program, command or script. Mount/\Commands
are invoked using the syntax
%.Command%
In the example below:
ntlib = Advanced NT/2K/XP Command Library (FREE)
/q = switch for Quiet Mode (no banner or onscreen updates)
FNL = File_Number_Lines (procedure to add line numbers to any text file)
%_FNL% = output variable containing the name of the numbered file
Redir_Demo.cmd = Example script for Redir Rapids commands
*******
C:\GuardPost>ntlib /q fnl
SYNTAX.....: ntlib :[FNL|File_Number_Lines] [drive:][path]FileName
DESCRIPTION: Number the lines in a file, padding the line numbers with 0's.
PARAMETERS.: FileName = Source file to number. (also accepts UNC format)
VARIABLES..: _FNL = Name of the numbered output file.
EXAMPLES...: "ntlib :FNL FileName.Ext"
-Returns FileName.Ext.Numbered.txt in current directory.
-Line numbers are separated from the file content by ". "
(one period followed by one space).
Example: "001. This is the first line of text"
"002. This is the second line of text"
|||.
"010. This is the tenth line of text"
NOTES......: Maximum number of lines = 999.
The "REAL" :FNL (included with NTCmdLib.cmd) can number files
as
_ large as 999999999 (One Billion minus 1) lines!
NTCmdLib's :FNL also accepts CustomDelimiters like "..: "
Example: "00001..: This is the first line of text"
"00002..: This is the second line of text"
|||..:
"97654..: This is the 97,654th line of text"
Custom delimiters enable using a character that you KNOW won't
be
_ present in your input file as a delimiter, thus preparing the
_ numbered output for further processing.
C:\GuardPost>ntlib /q :FNL Redir_Demo.cmd
C:\GuardPost>TYPE %_FNL%
01. @ECHO OFF
02.
03. :* Create a zero length file to use for the demo
04. %.ZeroFile% FileName.Ext
05.
06. IF EXIST FileName.Ext %.Silent% (
07. ECHO: {Silent} Normal Message 1
08. %.ErrEcho% {Silent} Error Message 1
09. )
10.
11. IF EXIST FileName.Ext %.Quiet% (
12. ECHO: {Quiet} Normal Message 2
13. %.ErrEcho% {Quiet} Error Message 2
14. )
15.
16. IF EXIST FileName.Ext %.Kity% (
17. ECHO: {Kity} Normal Message 3
18. %.ErrEcho% {Kity} Error Message 3
19. )
20.
21. IF EXIST FileName.Ext %.Show% (
22. ECHO: {Show} Normal Message 4
23. %.ErrEcho% {Show} Error Message 4
24. )
25.
26. IF EXIST FileName.Ext %.ShowErr% (
27. ECHO: {ShowErr} Normal Message 5
28. %.ErrEcho% {ShowErr} Error Message 5
29. )
30.
31. IF EXIST FileName.Ext %.ShowAll% (
32. ECHO: {ShowAll} Normal Message 6
33. %.ErrEcho% {ShowAll} Error Message 6
34. )
35.
36. :* Delete the demo file
37. DEL FileName.Ext
*******
[Normal Mode - No Redirection]
C:\GuardPost>Redir_Demo
{Quiet} Error Message 2
{Kity} Normal Message 3
{Show} Normal Message 4
{Show} Error Message 4
{ShowErr} Normal Message 5
{ShowErr} Error Message 5
{ShowAll} Normal Message 6
{ShowAll} Error Message 6
[Quiet Mode - Direct STDOUT to NUL]
C:\GuardPost>Redir_Demo >NUL
{Quiet} Error Message 2
{Show} Normal Message 4
{Show} Error Message 4
{ShowErr} Error Message 5
{ShowAll} Normal Message 6
{ShowAll} Error Message 6
[Silent Mode - Direct STDOUT and STDERR to NUL]
C:\GuardPost>Redir_Demo >NUL 2>NUL
{Show} Normal Message 4
{ShowErr} Error Message 5
{ShowAll} Normal Message 6
{ShowAll} Error Message 6
[Logging Mode - Direct STDOUT and STDERR to script.log]
C:\GuardPost>redir_demo >script.log 2>&1
{Show} Normal Message 4
{ShowErr} Error Message 5
{ShowAll} Normal Message 6
{ShowAll} Error Message 6
C:\GuardPost>type script.log
{Quiet} Error Message 2
{Kity} Normal Message 3
{Show} Error Message 4
{ShowErr} Normal Message 5
*******
Note that even when redirecting all script output to a log file, you can
force a message to the console using Show, ShowErr or ShowAll. This is
often more convenient (and easy to understand) than repeatedly watching the
end of script.log to see how far along the script is in it's processing.
*******
The following commands are included in the FREE ntlib.cmd
Quiet
Kity
Silent
ErrEcho
Additional commands included in the Standalone Mount/\Command Set
(MtCmds.cmd)
Show
ShowErr
ShowAll
ZeroFile
*******
ZeroFile - Creates a zero-byte file or
"zeroes out" an existing file
KITY=Keep It To Yourself (i.e., suppress errors only)
*******
Notes:
1. .Mount/\Commands are constructed using ONLY builtin
commands common to all four platforms (NT/2K/XP/K3).
2. .M/\C's are NOT case sensitive. Mixed case is used
for visual clarity only.
3. ntlib.cmd provides over 100 resources to assist with
writing and documenting cross-platform scripts,
including 57 .Mount/\Commands. You can obtain it
(for FREE) at (http://ntlib.com).
4. Information about the Standalone .Mount/\Command Set
can be found at (http://MountCommands.com).
*******
TheGuardBook contains a "Mounted Help" page for each internal cmd.exe
command. This is a single color-coded page, highlighting the differences
among the NT/2K/XP/K3 versions. The complete help text for each OS is also
available for comparison (http://TheSystemGuard.com/TheGuardBook/CCS-Int.)
*******
-tsg
__________________________________________________ __________
TheSystemGuard.com | BoomingOrFuming.com | MountCommands.com
Free and "Almost Free" Knowledge for Windows System Admins!
"leo" > wrote in message
...
> Hi,
>
> How can I create a log of within a dos script. I would
> like to execute a list of commands and create a log of the
> process. How can I do that.
>
> Thanks in advance
(re)direct the output of any program, command or script. Mount/\Commands
are invoked using the syntax
%.Command%
In the example below:
ntlib = Advanced NT/2K/XP Command Library (FREE)
/q = switch for Quiet Mode (no banner or onscreen updates)
FNL = File_Number_Lines (procedure to add line numbers to any text file)
%_FNL% = output variable containing the name of the numbered file
Redir_Demo.cmd = Example script for Redir Rapids commands
*******
C:\GuardPost>ntlib /q fnl
SYNTAX.....: ntlib :[FNL|File_Number_Lines] [drive:][path]FileName
DESCRIPTION: Number the lines in a file, padding the line numbers with 0's.
PARAMETERS.: FileName = Source file to number. (also accepts UNC format)
VARIABLES..: _FNL = Name of the numbered output file.
EXAMPLES...: "ntlib :FNL FileName.Ext"
-Returns FileName.Ext.Numbered.txt in current directory.
-Line numbers are separated from the file content by ". "
(one period followed by one space).
Example: "001. This is the first line of text"
"002. This is the second line of text"
|||.
"010. This is the tenth line of text"
NOTES......: Maximum number of lines = 999.
The "REAL" :FNL (included with NTCmdLib.cmd) can number files
as
_ large as 999999999 (One Billion minus 1) lines!
NTCmdLib's :FNL also accepts CustomDelimiters like "..: "
Example: "00001..: This is the first line of text"
"00002..: This is the second line of text"
|||..:
"97654..: This is the 97,654th line of text"
Custom delimiters enable using a character that you KNOW won't
be
_ present in your input file as a delimiter, thus preparing the
_ numbered output for further processing.
C:\GuardPost>ntlib /q :FNL Redir_Demo.cmd
C:\GuardPost>TYPE %_FNL%
01. @ECHO OFF
02.
03. :* Create a zero length file to use for the demo
04. %.ZeroFile% FileName.Ext
05.
06. IF EXIST FileName.Ext %.Silent% (
07. ECHO: {Silent} Normal Message 1
08. %.ErrEcho% {Silent} Error Message 1
09. )
10.
11. IF EXIST FileName.Ext %.Quiet% (
12. ECHO: {Quiet} Normal Message 2
13. %.ErrEcho% {Quiet} Error Message 2
14. )
15.
16. IF EXIST FileName.Ext %.Kity% (
17. ECHO: {Kity} Normal Message 3
18. %.ErrEcho% {Kity} Error Message 3
19. )
20.
21. IF EXIST FileName.Ext %.Show% (
22. ECHO: {Show} Normal Message 4
23. %.ErrEcho% {Show} Error Message 4
24. )
25.
26. IF EXIST FileName.Ext %.ShowErr% (
27. ECHO: {ShowErr} Normal Message 5
28. %.ErrEcho% {ShowErr} Error Message 5
29. )
30.
31. IF EXIST FileName.Ext %.ShowAll% (
32. ECHO: {ShowAll} Normal Message 6
33. %.ErrEcho% {ShowAll} Error Message 6
34. )
35.
36. :* Delete the demo file
37. DEL FileName.Ext
*******
[Normal Mode - No Redirection]
C:\GuardPost>Redir_Demo
{Quiet} Error Message 2
{Kity} Normal Message 3
{Show} Normal Message 4
{Show} Error Message 4
{ShowErr} Normal Message 5
{ShowErr} Error Message 5
{ShowAll} Normal Message 6
{ShowAll} Error Message 6
[Quiet Mode - Direct STDOUT to NUL]
C:\GuardPost>Redir_Demo >NUL
{Quiet} Error Message 2
{Show} Normal Message 4
{Show} Error Message 4
{ShowErr} Error Message 5
{ShowAll} Normal Message 6
{ShowAll} Error Message 6
[Silent Mode - Direct STDOUT and STDERR to NUL]
C:\GuardPost>Redir_Demo >NUL 2>NUL
{Show} Normal Message 4
{ShowErr} Error Message 5
{ShowAll} Normal Message 6
{ShowAll} Error Message 6
[Logging Mode - Direct STDOUT and STDERR to script.log]
C:\GuardPost>redir_demo >script.log 2>&1
{Show} Normal Message 4
{ShowErr} Error Message 5
{ShowAll} Normal Message 6
{ShowAll} Error Message 6
C:\GuardPost>type script.log
{Quiet} Error Message 2
{Kity} Normal Message 3
{Show} Error Message 4
{ShowErr} Normal Message 5
*******
Note that even when redirecting all script output to a log file, you can
force a message to the console using Show, ShowErr or ShowAll. This is
often more convenient (and easy to understand) than repeatedly watching the
end of script.log to see how far along the script is in it's processing.
*******
The following commands are included in the FREE ntlib.cmd
Quiet
Kity
Silent
ErrEcho
Additional commands included in the Standalone Mount/\Command Set
(MtCmds.cmd)
Show
ShowErr
ShowAll
ZeroFile
*******
ZeroFile - Creates a zero-byte file or
"zeroes out" an existing file
KITY=Keep It To Yourself (i.e., suppress errors only)
*******
Notes:
1. .Mount/\Commands are constructed using ONLY builtin
commands common to all four platforms (NT/2K/XP/K3).
2. .M/\C's are NOT case sensitive. Mixed case is used
for visual clarity only.
3. ntlib.cmd provides over 100 resources to assist with
writing and documenting cross-platform scripts,
including 57 .Mount/\Commands. You can obtain it
(for FREE) at (http://ntlib.com).
4. Information about the Standalone .Mount/\Command Set
can be found at (http://MountCommands.com).
*******
TheGuardBook contains a "Mounted Help" page for each internal cmd.exe
command. This is a single color-coded page, highlighting the differences
among the NT/2K/XP/K3 versions. The complete help text for each OS is also
available for comparison (http://TheSystemGuard.com/TheGuardBook/CCS-Int.)
*******
-tsg
__________________________________________________ __________
TheSystemGuard.com | BoomingOrFuming.com | MountCommands.com
Free and "Almost Free" Knowledge for Windows System Admins!
"leo" > wrote in message
...
> Hi,
>
> How can I create a log of within a dos script. I would
> like to execute a list of commands and create a log of the
> process. How can I do that.
>
> Thanks in advance