Computer Hope

Microsoft => Microsoft DOS => Topic started by: timrob on January 24, 2010, 04:45:28 PM

Title: Copy DOS screen after it's Displayed
Post by: timrob on January 24, 2010, 04:45:28 PM
Is there a way to copy a DOS screen to a text file via a batch file, after it's displayed in the command window?

I'm running a batch file, if one of the commands fails, I only want to log the DOS screen if it fails.

I know how to start a log from the beginning, but that's one more process I don't want to run if not necessary.
Title: Re: Copy DOS screen after it's Displayed
Post by: BillRichardson on January 24, 2010, 05:11:09 PM
Is there a way to copy a DOS screen to a text file via a batch file, after it's displayed in the command window?


C:\batch>type  timrob.bat

Code: [Select]
@echo off

type timrob.txt


echo.  >> timrob.txt

type timrob.txt  >>  timrob2.txt

echo. >>  timrob2.txt

type  timrob2.txt

Output:

C:\batch>timrob.bat

Copy DOS screen after it's Displayed



Is there a way to copy a DOS screen to a text file via a batch file,
after it's displayed in the command window?

I'm running a batch file, if one of the commands fails, I only want
to log the DOS screen if it fails.

I know how to start a log from the beginning, but that's one more
process I don't want to run if not necessary.
Copy DOS screen after it's Displayed



Is there a way to copy a DOS screen to a text file via a batch file,
after it's displayed in the command window?

I'm running a batch file, if one of the commands fails, I only want
to log the DOS screen if it fails.

I know how to start a log from the beginning, but that's one more
process I don't want to run if not necessary.

Copy DOS screen after it's Displayed



Is there a way to copy a DOS screen to a text file via a batch file,
after it's displayed in the command window?

I'm running a batch file, if one of the commands fails, I only want
to log the DOS screen if it fails.

I know how to start a log from the beginning, but that's one more
process I don't want to run if not necessary.


C:\batch>
Title: Re: Copy DOS screen after it's Displayed
Post by: BillRichardson on January 24, 2010, 05:17:16 PM
1) Point to Bar at top of screen, right click, choose select all
and then  choose copy
2) Paste to image editor and save
3) Upload to phobucket.com
4) Copy image code and paste image code  to here

(http://i7.photobucket.com/albums/y268/billrich/cpscreen.jpg)
Title: Re: Copy DOS screen after it's Displayed
Post by: Helpmeh on January 24, 2010, 07:28:38 PM
To check if a command fails, add this on the SAME LINE after the desired command.

&& Echo "INSERT COMMAND HERE" failed - %time% - %date% >errors.log
Title: Re: Copy DOS screen after it's Displayed
Post by: Dusty on January 24, 2010, 09:51:15 PM
Helpmeh - you sure about that?  Should the character not be || for failure?

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds_shelloverview.mspx?mfr=true
Quote
&& Use to run the command following && only if the command preceding the symbol is successful. Cmd.exe runs the first command, and then runs the second command only if the first command completed successfully.

|| Use to run the command following || only if the command preceding || fails. Cmd.exe runs the first command, and then runs the second command only if the first command did not complete successfully (receives an error code greater than zero).
Title: Re: Copy DOS screen after it's Displayed
Post by: Helpmeh on January 25, 2010, 08:40:39 AM
Helpmeh - you sure about that?  Should the character not be || for failure?

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds_shelloverview.mspx?mfr=true
Hmmm...I thought it was the other way around. Oh well, good for you for catching that.
Title: Re: Copy DOS screen after it's Displayed
Post by: Salmon Trout on January 25, 2010, 11:25:14 AM
Hmmm...I thought it was the other way around. Oh well, good for you for catching that.

How hard is it to test?

Code: [Select]
C:\>set test=eggs

C:\>echo %test% | find "eggs">nul && echo success
success

C:\>@echo %test% | find "bacon">nul || echo failure
failure
Title: Re: Copy DOS screen after it's Displayed
Post by: Helpmeh on January 25, 2010, 11:48:20 AM
How hard is it to test?

Code: [Select]
C:\>set test=eggs

C:\>echo %test% | find "eggs">nul && echo success
success

C:\>@echo %test% | find "bacon">nul || echo failure
failure
Well I don't think you can make batch scripts on an iPod Touch.
Title: Re: Copy DOS screen after it's Displayed
Post by: Salmon Trout on January 25, 2010, 12:39:51 PM
Well I don't think you can make batch scripts on an iPod Touch.

I guess... maybe one day you'll get a proper computer?
Title: Re: Copy DOS screen after it's Displayed
Post by: timrob on January 25, 2010, 02:17:43 PM
Helpmeh,
As an example, I used
Echo xcopy failed - %time% - %date% >errors.log
without the && and it works.  I don't know what the && are for.

I'll try to incorporate the new code into the batch file.  In my old code, to confirm the batch file was copying correctly, I was comparing the number of megabytes.  My way was a much longer way.

I was also using xcopy with /v. 

Bill,
I just get blank files with your code.
Title: Re: Copy DOS screen after it's Displayed
Post by: Geek-9pm on January 25, 2010, 02:32:37 PM
I am watching this thread. Does the OP really mean that he wants to capture the errors messages as a text file and he does not know where the error will occur?
And this all has to be in batch file and run without operator assistance? He wants something to read the text from the screen?
Can you do that inside of DOS?


Title: Re: Copy DOS screen after it's Displayed
Post by: timrob on January 25, 2010, 02:54:03 PM
I am watching this thread. Does the OP really mean that he wants to capture the errors messages as a text file and he does not know where the error will occur?
And this all has to be in batch file and run without operator assistance? He wants something to read the text from the screen?
  Yes, that's what I'm asking.  I don't know if it's possible.
Title: Re: Copy DOS screen after it's Displayed
Post by: BillRichardson on January 25, 2010, 03:47:29 PM
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/redirection.mspx?mfr=true

Timrob:

Does the Timrob really mean that he wants to capture the errors messages
as a text file?


Standard Input, Standard Output, and Standard Error
When a command begins running, it usually expects that three files are
already open: standard input, standard output, and standard error
(sometimes called error output or diagnostic output). A number,
called a file descriptor, is associated with each of these files, as follows:
File descriptor 0  Standard input 
File descriptor 1  Standard output 
File descriptor 2  Standard error (diagnostic) output


Standard error, sometimes denoted as stderr, is where error messages go.
By default, this is your screen.


These default actions of input and output can be varied.


We can use a file as input and write results of a command to a file.
This is called input/output redirection, ">" or ">>" 

 

Use redirection, "2>", to a text file for the error message.

We can easily display a message to the screen from a text file.
The type command?
Notepad?


Redirection
You may be familiar with "redirection to NUL" to hide command output:

ECHO Hello world>NULwill show nothing on screen.
That's because >NUL redirects all Standard Output to the NUL device, which does nothing but discard it.

EHCO Hello world>NUL
Title: Re: Copy DOS screen after it's Displayed
Post by: timrob on January 25, 2010, 04:06:16 PM
Sorry, I misread your statement.  I meant I wanted to capture what ever is on the DOS screen.
Title: Re: Copy DOS screen after it's Displayed
Post by: BillRichardson on January 25, 2010, 04:17:20 PM
I meant I wanted to capture what ever is on the DOS screen.

Capture with redirection to a text file before a screen display. Do not allow a screen display.

( You may latter display the contents of the text file to the screen.)
Title: Re: Copy DOS screen after it's Displayed
Post by: BillRichardson on January 27, 2010, 11:33:04 AM
Is there a way to copy a DOS screen?



(http://i7.photobucket.com/albums/y268/billrich/copydisplay.jpg)
Title: Re: Copy DOS screen after it's Displayed
Post by: Geek-9pm on January 27, 2010, 01:18:09 PM
They may be a limit of about 7 screens. When I scroll the screen it looks like about seven pages and the it truncates pages before that. So a screen capture would not get as much data as the redirection.
Title: Re: Copy DOS screen after it's Displayed
Post by: Salmon Trout on January 27, 2010, 01:24:33 PM
They may be a limit of about 7 screens. When I scroll the screen it looks like about seven pages and the it truncates pages before that. So a screen capture would not get as much data as the redirection.

You can edit the screen buffer size (H: chars V: lines) in the cmd window properties.
Title: Re: Copy DOS screen after it's Displayed
Post by: Geek-9pm on January 27, 2010, 01:32:51 PM
You can edit the screen buffer size (H: chars V: lines) in the cmd window properties.

Great! Now how do you find the pointer to the screen buffer? And is it a 32 bit absolute address? If so, you could compile a simple C# program to grab the whole thing and put it into a file. You would run it after the batch was all done. Theat way you would not have to modify the batch in any way. other that starting the screen buffer grabber at the end of the job.

Is that what he wants?

Title: Re: Copy DOS screen after it's Displayed
Post by: BillRichardson on January 27, 2010, 01:35:46 PM
They may be a limit of about 7 screens. When I scroll the screen it looks like about seven pages and the it truncates pages before that. So a screen capture would not get as much data as the redirection.

The setup for the screen shot and text capture are similar.

Then,

1) Either PrintScreen key for a screen shot.
or
2) click copy for text capture
or
3) Redirection before the text is displayed

Which method does TimRob need?
Title: Re: Copy DOS screen after it's Displayed
Post by: Salmon Trout on January 27, 2010, 01:38:13 PM
Great! Now how do you find the pointer to the screen buffer? And is it a 32 bit absolute address? If so, you could compile a simple C# program to grab the whole thing and put it into a file. You would run it after the batch was all done. Theat way you would not have to modify the batch in any way. other that starting the screen buffer grabber at the end of the job.

Is that what he wants?



http://msdn.microsoft.com/en-us/library/ms682073%28VS.85%29.aspx
Title: Re: Copy DOS screen after it's Displayed
Post by: ghostdog74 on January 27, 2010, 07:24:56 PM
Sorry, I misread your statement.  I meant I wanted to capture what ever is on the DOS screen.

whatever is on the DOS screen is whatever your DOS batch program spewed out via echo statements. Therefore, you can just redirect them to a file using > or >>. The rest of what's on your DOS screen are the cmd.exe prompt, plus whatever text you type in, which I don't really know why you want to capture them as well.
Title: Re: Copy DOS screen after it's Displayed
Post by: Geek-9pm on January 27, 2010, 08:08:48 PM
There used to be, sometime in the dim past, a way to redirect all console output to a serial port. Would that be a hardware method?
I think taht is still used when doing debugging on some kinds of system programs.
Title: Re: Copy DOS screen after it's Displayed
Post by: BC_Programmer on January 27, 2010, 08:19:36 PM
Great! Now how do you find the pointer to the screen buffer? And is it a 32 bit absolute address? If so, you could compile a simple C# program to grab the whole thing and put it into a file. You would run it after the batch was all done. Theat way you would not have to modify the batch in any way. other that starting the screen buffer grabber at the end of the job.

Is that what he wants?


http://msdn.microsoft.com/en-us/library/ms682073%28VS.85%29.aspx

Main issue being that you'd need to somehow acquire the console handle, and even then I don't think you'd have much luck, since handles aren't accessible cross-process.

Quote
And is it a 32 bit absolute address? If so, you could compile a simple C# program to grab the whole thing and put it into a file.

Have you ever used C#? or programmed for the NT environment?

First: it doesn't matter if you had a pointer. every memory pointer is only valid within the address space of a single process. you cannot, for example, take a handle to a string from one program and access that string in another program using that pointer; it simply doesn't work that way. Two programs can be running at the same time that have pointers that are the same but point to other items. Thus is the benefit of protected memory space and Virtualization.

Additionally, even IF that was possible C# doesn't really give you any easy way of using direct pointers. C does, though it wouldn't be simple. How would you determine the size of the buffer? you don't, your pretty much forced to guess, and chances are you'll overrun that storage area and start emitting some other stuff from elsewhere.


There used to be, sometime in the dim past, a way to redirect all console output to a serial port. Would that be a hardware method?
I think taht is still used when doing debugging on some kinds of system programs.


Yes. that's still possible. If you have a checked build of windows (read: dev build). And it doesn't output "Console" data it outputs messages direct from the kernel.
Title: Re: Copy DOS screen after it's Displayed
Post by: Geek-9pm on January 27, 2010, 08:54:53 PM
Thank you , BC_Programmer,
No I have not down programming is a NT environment. NT was after my days. I did assembly language in the old DOS environment . We just had to know where the segment was. I used to do this like this:
Code: [Select]
     ...
     push cs
     pop dx
    ...
Well, that is all i can remember, am not sure if it means anything anymore.
Title: Re: Copy DOS screen after it's Displayed
Post by: BC_Programmer on January 27, 2010, 09:38:27 PM
Thank you , BC_Programmer,
No I have not down programming is a NT environment. NT was after my days. I did assembly language in the old DOS environment . We just had to know where the segment was. I used to do this like this:
Code: [Select]
     ...
     push cs
     pop dx
    ...
Well, that is all i can remember, am not sure if it means anything anymore.


yep, good ol' Segment:offset, IIRC; actually, although MS seems to claim otherwise in their literature, Win 9x never had a "protected memory model" you could inspect the memory of any process through ASM in a DEBUG session, I think.

being based on a "protected memory pre-emptive tasking environment" was one of the requirements MS had to meet in order to get into the government market; It's more secure for the same reasons it's more difficult to work with in some scenario's. If you could inspect a command sessions memory for the command buffer you could just as easily inspect "super high profile banking application" for passwords stored directly in variables; or, if the program is designed properly, you'd be able to inspect the memory contents after the user typed in the super ultra secure password and copy it down. Of course they are contrived examples but it prevents spyware from being used against the government too much.

On the other hand, it's still possible to inspect the memory of any process; the trick is to get a piece of code to run within that process, and then communicate (perhaps via named pipes) to the "main" process that collects the information. There are a few methods of injecting code into other processes, but it's rather involved. the "easy" way is to simply write a small DLL that get's loaded via the appInit_DLLs key in the registry; then there will be a DLL loaded into every single EXE process that starts, and that problem is solved; and Interprocess communication can be initiated between any process since that process will have "your" DLL loaded.
Title: Re: Copy DOS screen after it's Displayed
Post by: Geek-9pm on January 27, 2010, 10:04:00 PM
To get back to the OP. You wold have to get the CMD.EXE to load another DLL that would  "SPY" on the memory assignment.
In the OP, he said in a batch file. Maybe he did not know that for a one-time thing anybody can do it manually by scrolling back into the screen buffer and then select EDIT MARK COPY and then open notepad and paste it into notepad.

When he said batch. and screen capture i took him literally.

We should have asked what he might earlier.