"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Do you need to log the output of all the commands in your batch file?
Different methods may be needed depending on the specific command,
but typically you can pipe the output to a file using redirection characters.
For example, if you have a batch file like this:

The first "greater than" redirection character creates the log.txt file
and writes the batch command's output to the file.
Subsequently using two redirection characters appends the next command's output
to the file. If only one redirection character is used, it overwrites the log file if it exists,
creating a new log. You can do that each time, or use two characters on the first command
to append the results to a previously created log file. Or perhaps have your batch file
copy the log elsewhere if you need to save it.
(The last line is just to open the log file in Notepad.)

Other commands can be combined to format the output
depending on exactly what you want logged.
If this isn't what you need, post back with your batch file, if possible,
and which of its commands you need to log and we'll get it to work.

To slow the scroll there are several techniques like <ctrl>S or use of the KB key <pause>, but being lazy, I usually use similar redirects, sometimes with a command to CD, and usually with command to also redirect the date, maybe even the time if the logfile is to remain around awhile.

I usually code the same...
Except the last line would be either:
Type log.txt
or:
Type log.txt|more

In your case I'd use the latter, for you seem to want the scroll help. Drawback if not on Win2K is that to go back you'd have to manually reenter the command to display it on-screen. Advantage is you don't need windows. Without Windows running (perhaps exiting to DOS before Win9x kicks in) you could include the Edit command.

:-) Thanx Rin, I do usually run in Windows, and keep a NotePad window open, on the side, to view it, but for some reason never thought to actually run it from within the batch command itself! My Gosh!

0

cma1Author Commented: 2001-07-20

Rin, I am not quite sure what you are saying to do.

I want a log of the screen output.
Are you saying to insert > log.txt after each line,
or just the first line, with >> log.txt in the all subsequent lines or
> log.txt in the first line
>> log.txt in the second line
>>> log.txt in the third line, etc.?

I am simply trying to get a log of the screen output.
I thought that there was some simple DOS command that would do that.

The first "greater than" redirection character creates the log.txt file
and writes the batch command's output to the file.
Subsequently using two redirection characters appends the next command's output
to the file. If only one redirection character is used, it overwrites the log file if it exists,
creating a new log. You can do that each time, or use two characters on the first command
to append the results to a previously created log file. Or perhaps have your batch file
copy the log elsewhere if you need to save it.
(The last line is just to open the log file in Notepad.)

Hi cma... Essentially what I was saying is the second scenario you mention;
append > log.txt to the end of the first line to be logged,
then append >> log.txt to each subsequent line.

Using only one redirection character will create a new file having the name specified,
(in this case log.txt) or will overwrite a file with that name if it exists.
Using two of these redirection characters will append to the file.

Alternatively, if you use two characters on the first line (as well as all other lines)
it will either create a new file having the name specified (if it doesn't exist)
or will append to a file with that name if it does exist. (e.g., if adding to a previous log)
So using one character either creates or overwrites and using two characters append.

Please wait just a little while and I'll provide some more info that I think you can use...
Was wondering if your batch script has many commands, or just a few,
and whether you need to log only the results of the COPY command...
(i.e., as opposed to XCOPY or any other commands you may have in the script.)
With your script I could offer some specific suggestions, though it's not necessary
and can still provide some examples which can be adapted to your situation.
But wanted you to know I saw your post and will respond further directly.

cma1 is correct when logging the command it does not log any of the error messages that appear on the screen. For example I ran this bat file from the Start > Run while in Win 2000 and this is the result:

the command in the bat file is this
copy C:\WINNT\system32\config\*.* c:\~~~

the Run line command is this
C:\~~~\copy.bat >c:\~~~\Filecopy.txt
------------------------------------------

C:\WINNT\system32\config\USERDIFF
C:\WINNT\system32\config\SYSTEM.SAV
C:\WINNT\system32\config\SOFTWARE.SAV
C:\WINNT\system32\config\DEFAULT.SAV
C:\WINNT\system32\config\NTUSER.DAT
C:\WINNT\system32\config\USRCLASS.DAT
C:\WINNT\system32\config\SecEvent.Evt
C:\WINNT\system32\config\IExplore.evt
C:\WINNT\system32\config\SECURITY
The process cannot access the file because it is being used by another process.
C:\WINNT\system32\config\SYSTEM.ALT
The process cannot access the file because it is being used by another process.
C:\WINNT\system32\config\SAM
The process cannot access the file because it is being used by another process.
C:\WINNT\system32\config\SYSTEM
The process cannot access the file because it is being used by another process.
C:\WINNT\system32\config\SOFTWARE
The process cannot access the file because it is being used by another process.
C:\WINNT\system32\config\DEFAULT
The process cannot access the file because it is being used by another process.
C:\WINNT\system32\config\AppEvent.Evt
C:\WINNT\system32\config\SysEvent.Evt
10 file(s) copied.
---------------------------------------------------------

So the error messages are not making it to log file but cma1 wants these messages in the log file.

Sorry for the delayed response... I'd put together a few notes and methods
to log your copy process results, going on the info you provided
about having a batch file that "copies lots of files to a backup directory"
but now I see the additional info here...
Most of what I wrote is probably not applicable to what you want so I'll try again...

You mention the "x file(s) copied" messages and "Access denied" message
and I wondered if you also need to log the listing of the filenames that scroll by...
I presumed an ongoing log, but is this merely to troubleshoot the errors mentioned?
You say there are "many Copy commands in the batch file..."
Your example of the "8 files copied" message indicates that some of your
COPY commands uses wildcards? I figured a batch file with a just a few lines like
"copy c:\windows\*.* c:\bakupdir" but is it that you have too many COPY commands
to easily edit? As indicated, you're "trying to get a log of the screen output."
and refer to "some simple DOS command that would do that."
The commands are simple, but may need to be coded at various places
throughout the script. And note that what is logged and how it's logged
may be specific to the command.

Your examples posted of the "various messages" suggest the COPY command...
(With XCOPY you may get "Access is denied"...) When the COPY command
generates the two-word variation (Access denied) it's usually when trying to
overwrite a file having its Read-Only attribute set. At that point the batch script
may terminate, logging is discontinued and additional messages
won't occur in the log anyway.

So if you're trying to gather info on COPY errors that occur when running your batch file,
it may be best to first eliminate known potential errors... Then you may need to
rewrite the script using alternate commands. (Seeing the batch script might change things
but it shouldn't be too difficult... even using a text editor's find/replace feature
to edit a very long script...) But other commands can eliminate some of the errors
and better show you what is occurring.

For example, the "Access denied" message generated when trying to
copy over a Read-Only file can be eliminated by first using ATTRIB to clear the attributes
of existing files in the directory to where you're copying.
To clear the Read-Only, System and Hidden attributes of all files
in the C:\BakupDir and all its subdirectories before copying there,
add the ATTRIB command before the copy process begins in your script, like:

ATTRIB -R -S -H C:\BakupDir /S

Some of these error messages are generated in Windows by kernel32.dll and
won't necessarily be redirected to a file (nor would apply in DOS mode.)
An example is the "Sharing Violation" error which you may be getting.
If you try to copy a file that is "in use" such as the Windows swap file,
you'd see something like:

Sharing violation - C:\WINDOWS\WIN386.SWP
0 file(s) copied

Trying the same thing with XCOPY you'd get a message similar to:

Error copying file C:\WINDOWS\WIN386.SWP ...
The process cannot access the file because it is being used by another process.
0 File(s) copied

The "0 file(s) copied" is logged but the remaining portion is not.
(In DOS mode, the file won't be "in use" and can be copied or deleted or whatever,
so the error wouldn't occur. The circumstances depend on what you're copying
and whether your script contains only COPY commands.)
The error messages pertaining to COPY mentioned above,
and others you may be concerned with such as
"Invalid directory," "Invalid filename," "File not found," "Invalid path," etc.,
may not be redirected but will still write the message "0 file(s) copied" ...
If you do a command like this:

COPY C:\Windows\*.* C:\BakupDir >> ~Results.txt

...you'll get a list of the filenames, etc, redirected to ~Results.txt ...
(If copying "lots of files" as you say, you may not see screen activity,
as it's now being redirected to the file. Without checking for drive activity,
it may not be apparent that something's happening.)
Doing it like that, the generated list wouldn't tell you much...
But if you call each file individually using the FOR command, like:

FOR %%x in (C:\Windows\*.*) do COPY %%x C:\BakupDir >> ~Results.txt

...you'll get a list having the results of the command that is run on each file, like:
"1 file(s) copied", "0 file(s) copied", "1 file(s) copied," and so on...
(The "0 file(s) copied" message is also generated when trying to copy a zero-byte file,
which won't be copied.)

But the COPY procedures above would probably fail on the mentioned errors
and even if not, neither of the logs produced would be very useful...
So the idea is to substitute XCOPY and use it for the copy process and
get its differing output to create a useful log... Mostly though, XCOPY has features
more suitable to copying numerous files, especially in Windows...
I'll add some info about it, but here's a way to get all of the error messages in Windows
to a hard copy or file.

You can use the CTTY command to choose the output device and
can change the device from the console (CON) to the printer (PRN) ...
This will write the output to the printer port including the
Windows generated messages not logged.
The syntax in a batch script would be like:

CTTY PRN
COPY C:\Windows\*.* C:\BakupDir
CTTY CON

Add CTTY PRN to the beginning of the script and be sure to send control
back to the console device (CTTY CON) at the end of the script.
This method will allow you to print the entirety of what you indicate is
scrolling by on the screen too fast. Of course, with an extensive script,
there's a question of printer paper, so you probably wouldn't want to
log this way each time.

But you can use this method and tell Windows to "print to a file" instead of to the printer
and create your text log of the batch process. A way to do it is like this:
Open the Printer app and do "Add Printer" to run the Wizard...
From the list of "Manufacturers" choose "Generic"
and then choose "Generic/Text Only"...
Now print to that driver when you want to create the log file.
(You'll be prompted for a filename or you can designate a permanent name.)
With that and those two CTTY commands you can log everything.

Here's some more info about using XCOPY instead of COPY in your script...
Substituting XCOPY in my previous FOR example to copy and create a log, like:

FOR %%x in (C:\Windows\*.*) do XCOPY %%x C:\BakupDir >> ~Results.txt

...produces a log having both the filename and the results. So using the above,
if the Windows directory contains WIN.INI, SYSTEM.INI and WIN386.SWP
and the BakupDir already contains a SYSTEM.INI with its Read-Only attribute set,
you'd get a log similar to:

Another benefit of this is that the output above is redirected to the ~Results.txt file,
but only the "unlogged" error messages are displayed on the screen, like:

Error copying file C:\WINDOWS\SYSTEM.INI to C:\BAKUPDIR\SYSTEM.INI
Access is denied.
Error copying file C:\WINDOWS\WIN386.SWP to C:\BAKUPDIR\WIN386.SWP
The process cannot access the file because it is being used by another process.

Since the other filenames aren't displayed on screen, the error messages will appear slowly
as they occur. It would then be possible to use the Pause key (if necessary with many errors)
and/or print the screen to get only the error messages.

To eliminate the copy process failing, you can use the XCOPY /C switch,
which allows it to continue copying when errors occur.
So with the FOR command it would be like:

FOR %%x in (C:\Windows\*.*) do XCOPY/C %%x C:\BakupDir >> ~Results.txt

There are other useful XCOPY switches when copying one or multiple files in Windows,
especially for batch use... The /Y switch tells XCOPY to not prompt for Yes or No
when attempting to overwrite an existing file from the command prompt,
but you can produce the same results of displaying only error messages to the screen
(and not all the filenames) using the /Q (quiet) switch like:

XCOPY /Q /C /Y C:\Windows\*.* C:\BakupDir

That may be all you need to simply see the errors.
Here are other handy XCOPY switches under Windows:

Also, if you're periodically backing up the same group of files,
the XCOPY /D switch will copy only files that have been modified since the last backup.
That way you're not redundantly copying the same exact file each time.
Although you may have to redo portions of your script,
XCOPY can give you much more control.

If you create a ~Results.txt file using these commands:

FOR %%x in (C:\Windows\*.*) do XCOPYH/C/R/D %%x C:\BakupDir >> ~Results.txt

...you could then open and scan the ~Results.txt file for the string "0 File(s) copied"
and easily see the name of the file that wasn't copied.
You could also use FIND to isolate and write only that string to another file, like:

FIND/i " 0 File(" ~Results.txt >> ~CopyLog.txt

If testing the above, note that the two redirection characters will append to a file each time.
To create a new file, the existing copies should be deleted first, e.g., :

The " 0 File(" parameter of the FIND command is a portion of the string being sought
and can be replaced with whatever line you want to cull from the file.
The /i switch tells FIND to ignore case in the search string.

Using XCOPY and the appropriate switches you should be able to reduce the errors
to just the "Sharing Violation" error and would know that any occurrence of "0 File(s) copied"
would pertain to that error. If necessary, once the files are identified,
a separate script could copy those files in DOS mode.

Hopefully some of this will work for you... Otherwise post back with exactly what
and why you need logged and perhaps the batch script...
Some shortcuts or better methods to log may be found, or you can email it if you want,
but please ask if you have other questions about it...

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

It's time to clean up this topic area and that means taking care of this question. Your options at this
point are:

1. Award points to the Expert who provided an answer, or who helped you most. Do this by clicking on
the "Accept Comment as Answer" button that lies above and to the right of the appropriate expert's name.

2. PAQ the question because the information might be useful to others, but was not useful to you. To
use this option, you must state why the question is no longer useful to you, and the experts need to
let me know if they feel that you're being unfair.

3. Ask Community Support to help split points between participating experts. Just comment here with
details.

4. Delete the question because it is of no value to you or to anyone else. To use this option, you
must state why the question is no longer useful to you, and the experts need to let me know if they
feel that you're being unfair.

If you elect for option 2, 3 or 4, just post comment with details here and I'll take it from there.
We also request that you review any other open questions you might have and update/close them. Display
all your question history from your Member Profile to view details.

PLEASE DO NOT AWARD THE POINTS TO ME.

____________________________________________

Hi Experts:

In the event that the Asker does not respond, I would very much appreciate your opinions as to which
Expert ought to receive points (if any) as a result of this question. Likewise, you can also suggest
that I PAQ or delete the question.

Experts, please do not add further "answer" information to this question. I will be back in about one
week to finalize this question.

These comments are addressed to "Otta" in response to the petulant complaints above...
I meant to remain indifferent to this puerile contention, but as Otta's accusations
appear directed at me personally and considering the recent activity and 'cross_threads'
I should reply for the record.

(My apologies to cma1 for cluttering your question with pettiness...
I see in your other question concerning logging these specific messages
that you may have thought you deleted that one, but hopefully
some of the methods in this thread will give you the necessary info.)

Otta; There'd be less spam if you'd simply say what you mean...
If you have problems and think something is wrong here, take it up with Customer Service...
-else have the courage to address someone directly and cut the innuendo.

Regarding the CTTY thing; I wrote and tested portions of those comments
during the weekend before you posted anything about it, unaware that cma
had a question elsewhere... I composed that long before you referenced ctty...
Then I receive notification that you've joined the thread and (unsurprisingly)
see you calling questioner cma's comments "nonsense" and repeating a suggestion
which cma had already informed you doesn't work...
(btw... nfernand posts the correct syntax; "command.com /c batchfile.bat > log.txt"
if you want to see how to do it... But even so, 'your' method still doesn't provide a solution.)

You say it's "curious" that someone uses a command "mentioned" elsewhere by you...
That's your definition of plagiarism? I've dealt with many other questions regarding
the ctty command... Surely you don't think it's some undocumented secret
that only you're aware of? Are you implying nobody would've considered it
had you not brought it up? (you can call me al...) Note that I mention "redirection"
before you come in talking about it... How is that defined?
Regardless, you should take time to learn how to use a command
before commenting on it. Here's the gibberish from your two posts about it:

<<<<
Under DOS, first use the 'CTTY' command to divert _all_ output,
not just "standard output". Then, run the '.BAT' command.
Then, use 'CTTY' again, to "cancel" redirection.
>>>>

<<<<
Use the 'CTTY' ("change TTY") to divert _all_ output.
Run your '.BAT' file.
Use 'CTTY' to "cancel" the diversion.
Works under DOS!
>>>>

So what does that mean? How do you use the ctty command?
Where do you direct the output? In essence it means nothing...
You must supply a device name... The above will only generate an error
and waste someone's time... It won't work "under DOS" as you state
nor under Windows (which is what the question is about.)
So perhaps you can supply a working example (as I did)
of using ctty to log all of the screen output to a text file.
And btw... CTTY is an acronym for "Console TeleTYpe" ...
Not "change TTY" as you misstated.

And you still haven't expressed your point... Do you think you deserve some credit?
Fine with me... I suppose that's up to cma1... I've simply provided my notes on the
differing error messages and a few tested methods to first obviate some of the problem.
I wasn't even sure what messages needed logging until cma's confirmation
to the additional information CrazyOne posted. I provide methods to log all the messages
and the ctty thing is only a fraction of my input. I gave instructions and workarounds
in hopes of covering most situations. I tested everything proffered and it works as required.
I have no idea yet whether it will be of any use to cma... they're merely suggestions to try.
If you can find fault with any of it then please debug and redress it...
And if you can come up with a solution that works for cma, then that's even better.

Bottom line; keep your insinuations to yourself or complain in an appropriate manner.
A moderator monitors this ta to whom you can complain, who knows the subject
and probably doesn't want this unprofessionalism here. (Apologies to ComTech for mine.)
But if you want a couple more reasons why it's inconceivable
that I'd plagiarize your offered nonsense, please ask...

0

ComTechCommented: 2001-08-18

First, I would like to tell cma1, I did PAQ your question in Windows98 TA, as the Experts there agreed. Do you wany me to add the other 100 points to this question?

Regards,
ComTech
Community Support

0

ComTechCommented: 2001-08-18

I don't see any plagiarism about CTTY, most commonly used by the terminal device. The valid ports are: CON, AUX, COM1-4, LPT1-3, and NUL.

It's late, and I refused to go into detail about CTTY and it's effect in Dos commands and batch files. I will assure both, that it has been around for quite awhile, and have not known of any Copyrights.

Otta, just because you are aware of CTTY and it's uses, you're explination is not as explained enough for a new user, and that is how we have to look at most users, therefore they need more education and how to.

Before any of this started, I had an idea of who to award the question to, and since the user has not returned.

The question will go to rin1010 for his intensive instructions.

As the user did not return to either question, the points here in this TA will be doubled.

Thanks all,
ComTech
Community Support

0

ComTechCommented: 2001-08-18

Just a note, I hold myself exclusivily responsible for my own actions.

Regards,
ComTech

0

easoccerCommented: 2003-03-12

This thread is over, but I'd like to point out for future surfers that Ugi's answer was right on the mark:

-Start--------------------------------------
You can simply log the Output on STDOUT and STDERR with:
Command >log.txt 2>&1