@echo on

J

John A Grandy

if i use "@echo on" in a .bat file ....

how to have only the results of the commands echoed to the file, and not the
commands themselves ... ?
 
G

guard

how to have only the results of the commands echoed to the file, and not the
commands themselves ... ?

The "Redir Rapids" Series of .Mount/\Commands provide fine tuned control
over where the output of any program, command or script is directed. A
color-keyed version of the example below is at
(http://TheSystemGuard.com/MtCmds/RedirRapids/Show.htm).

*******

C:\GuardPost>ntlib /quiet :File_Number_Lines redir_demo.cmd

C:\GuardPost>set _fnl
_FNL=Redir_Demo.cmd.numbered.txt

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 normal output 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 normal output and errors to NUL]

C:\GuardPost>Redir_Demo >NUL 2>&1
{Show} Normal Message 4
{ShowErr} Error Message 5
{ShowAll} Normal Message 6
{ShowAll} Error Message 6

*******

ZeroFile - Creates a zero-byte file or
"zeroes out" an existing file

KITY - Keep It To Yourself
(i.e., suppress errors only)

*******

File_Number_Lines can also be invoked using it's short name:

ntlib :FNL FileToNumber

The name of the output file will be returned in the variable %_FNL%.

See an example at
(http://TheSystemGuard.com/NTCmdLib/Procedures/FNL.htm)

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

*******

TheGuardBook contains a "Mounted Help" page for each internal cmd.exe
command. This is a single color-keyed 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!
 
A

Al Dunbar

John,

A question: are you interested in learning about how to accomplish these
things in plain old ordinary batch, or are you interested in any solution
that works (like the mount commands might), regardless of the additional
learning curve plus having to download a third party tool such as that being
touted by Mr. "guard"?

If the former, then consider this:

@echo on
outputfile.txt dir "C:\program files"

When you run the above commands in a batch file, there should be no output
displayed in the command prompt window, and ONLY the output of the two
sample DIR commands will appear in the output file.

Some explanation: ">outputfile.txt" causes the output from the command given
to replace the previous content of the .txt file. ">>outputfile.txt" causes
the output to be appended to the end of the previous content of the .txt
file. In either case, if the .txt file had not previously existed, it will
be created.

If that is insufficient to answer your question, please provide more detail
as to exactly your situation.

/Al

guard said:
how to have only the results of the commands echoed to the file, and not the
commands themselves ... ?

The "Redir Rapids" Series of .Mount/\Commands provide fine tuned control
over where the output of any program, command or script is directed. A
color-keyed version of the example below is at
(http://TheSystemGuard.com/MtCmds/RedirRapids/Show.htm).

*******

C:\GuardPost>ntlib /quiet :File_Number_Lines redir_demo.cmd

C:\GuardPost>set _fnl
_FNL=Redir_Demo.cmd.numbered.txt

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 normal output 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 normal output and errors to NUL]

C:\GuardPost>Redir_Demo >NUL 2>&1
{Show} Normal Message 4
{ShowErr} Error Message 5
{ShowAll} Normal Message 6
{ShowAll} Error Message 6

*******

ZeroFile - Creates a zero-byte file or
"zeroes out" an existing file

KITY - Keep It To Yourself
(i.e., suppress errors only)

*******

File_Number_Lines can also be invoked using it's short name:

ntlib :FNL FileToNumber

The name of the output file will be returned in the variable %_FNL%.

See an example at
(http://TheSystemGuard.com/NTCmdLib/Procedures/FNL.htm)

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

*******

TheGuardBook contains a "Mounted Help" page for each internal cmd.exe
command. This is a single color-keyed 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!
 
H

Herb Martin

John A Grandy said:
if i use "@echo on" in a .bat file ....

how to have only the results of the commands echoed to the file, and not the
commands themselves ... ?

Read the other responses as they gave the details but note the
following

If you want EVERYTHING from the batch to go to a "log file"
then you must do the redirection (> log.txt) from OUTSIDE
the batch file on the invocation command, e.g.,

mybatch.cmd >log.txt

AND you must be running a recent OS since earlier ones
didn't support this (e.g., Win2000+, not sure about WinNT 4.0)

OR in the batch file (works for most OSs) you must redirect EACH
command.

Also useful is the ability to get the "Standard Error" either into the log
or disposed of to the "nul" device. The following work on NT and
Win2000+ at least:

(This one is very picky about order of the redirects):

mycommand >logfile.txt 2>&1

or (not so picky)

mycommand >logfile.txt 2>nul

The first one sends "standard output" to the file (can also be written
as 1>logfile.txt but that isn't necessary) and then it also sends "2"
or "Standard Error" to wherever "1-Standard Output" is going.

The second just discards "standard error" to the "nul" (nothing)
device.
 
G

Guest

Of course, consider this:

@echo off
echo C:\program files >outputfile.txt dir
echo C:\documents and settings >>outputfile.txt dir

Does exactly the same thing. :)
 
A

Al Dunbar

Of course, consider this:

@echo off
echo C:\program files >outputfile.txt dir
echo C:\documents and settings >>outputfile.txt dir

Does exactly the same thing. :)

In fact, that is the more common usage. I do it the other way around for two
reasons:

a) as a reminder that the command being executed is not what is processing
the redirection, that job belongs to the command pre-processor of cmd.exe.

b) to make it easy to verify that the filename is consistently correct.
consider these two examples, and let me know in which the error is most
apparent:
output.txt echo.short line

echo.short line >output.txt
echo.a much lengthier line, or so I consider it >>output.txt
echo.average length line >>output.txt
echo.a much lengthier line, or so I think >>output.txt
echo.short line >output.txt
echo.a much lengthier line, or so I consider it to be... >>output.txt


/Al
 
R

Roger Grossenbacher

how to have only the results of the commands echoed to the file, and not the
commands themselves ... ?

The "Redir Rapids" Series of .Mount/\Commands provide fine tuned control
over where the output of any program, command or script is directed. A
color-keyed version of the example below is at
(http://TheSystemGuard.com/MtCmds/RedirRapids/Show.htm).

*******

C:\GuardPost>ntlib /quiet :File_Number_Lines redir_demo.cmd

C:\GuardPost>set _fnl
_FNL=Redir_Demo.cmd.numbered.txt

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 normal output 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 normal output and errors to NUL]

C:\GuardPost>Redir_Demo >NUL 2>&1
{Show} Normal Message 4
{ShowErr} Error Message 5
{ShowAll} Normal Message 6
{ShowAll} Error Message 6

*******

ZeroFile - Creates a zero-byte file or
"zeroes out" an existing file

KITY - Keep It To Yourself
(i.e., suppress errors only)

*******

File_Number_Lines can also be invoked using it's short name:

ntlib :FNL FileToNumber

The name of the output file will be returned in the variable %_FNL%.

See an example at
(http://TheSystemGuard.com/NTCmdLib/Procedures/FNL.htm)

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

*******

TheGuardBook contains a "Mounted Help" page for each internal cmd.exe
command. This is a single color-keyed 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!
 
R

Roger Grossenbacher

John,

A question: are you interested in learning about how to accomplish these
things in plain old ordinary batch, or are you interested in any solution
that works (like the mount commands might), regardless of the additional
learning curve plus having to download a third party tool such as that being
touted by Mr. "guard"?

If the former, then consider this:

@echo on
outputfile.txt dir "C:\program files"

When you run the above commands in a batch file, there should be no output
displayed in the command prompt window, and ONLY the output of the two
sample DIR commands will appear in the output file.

Some explanation: ">outputfile.txt" causes the output from the command given
to replace the previous content of the .txt file. ">>outputfile.txt" causes
the output to be appended to the end of the previous content of the .txt
file. In either case, if the .txt file had not previously existed, it will
be created.

If that is insufficient to answer your question, please provide more detail
as to exactly your situation.

/Al

guard said:
how to have only the results of the commands echoed to the file, and not the
commands themselves ... ?

The "Redir Rapids" Series of .Mount/\Commands provide fine tuned control
over where the output of any program, command or script is directed. A
color-keyed version of the example below is at
(http://TheSystemGuard.com/MtCmds/RedirRapids/Show.htm).

*******

C:\GuardPost>ntlib /quiet :File_Number_Lines redir_demo.cmd

C:\GuardPost>set _fnl
_FNL=Redir_Demo.cmd.numbered.txt

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 normal output 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 normal output and errors to NUL]

C:\GuardPost>Redir_Demo >NUL 2>&1
{Show} Normal Message 4
{ShowErr} Error Message 5
{ShowAll} Normal Message 6
{ShowAll} Error Message 6

*******

ZeroFile - Creates a zero-byte file or
"zeroes out" an existing file

KITY - Keep It To Yourself
(i.e., suppress errors only)

*******

File_Number_Lines can also be invoked using it's short name:

ntlib :FNL FileToNumber

The name of the output file will be returned in the variable %_FNL%.

See an example at
(http://TheSystemGuard.com/NTCmdLib/Procedures/FNL.htm)

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

*******

TheGuardBook contains a "Mounted Help" page for each internal cmd.exe
command. This is a single color-keyed 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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top