Copying CMD.exe using batch file?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
reptilemikael
Posts: 1
Joined: 08 Mar 2019 12:22

Copying CMD.exe using batch file?

#1 Post by reptilemikael » 08 Mar 2019 12:28

is it possible to create a batch file to copy a open command prompt text? if so how? if not is there a different way?

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Copying CMD.exe using batch file?

#2 Post by aGerman » 10 Mar 2019 06:23

There is no command to copy the content of a console window programmatically. Right click on the title bar, Edit->Select all, then hit Enter to copy the content into the clipboard.

It would be possible to write a tool in another language to copy the content of the window from where the tool was called (EDIT okay, just wrote one https://sourceforge.net/projects/concpy/). But it wouldn't be reasonable to try to copy something out of a foreign window.

Steffen

Looge
Posts: 3
Joined: 25 Jun 2019 07:21

Re: Copying CMD.exe using batch file?

#3 Post by Looge » 25 Jun 2019 07:29

reptilemikael wrote:
08 Mar 2019 12:28
is it possible to create a batch file to copy a open command prompt text? if so how? if not is there a different way?
Maybe there is more clarification needed for your question, but how about this:

cmd.exe | tee C:\output.log

This will launch another session, but the TEE command will allow to :
- see the screen input/output as normal
- log (most) output to a file

The magic here is that contrary to all "normal" behaviour, the redirected output does not replace the normal screen output, it just adds redirected output to be logged, .. in addition to having normal output.
This is thanks to the TEE-function, which is a Unix/Linux thingy.
Many Windows port exist for it, like here: https://www.robvanderwoude.com/unixports.php

As stated, I'm not sure that is the kind of thing you are wanting to do, but if it is ..

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Copying CMD.exe using batch file?

#4 Post by dbenham » 26 Jun 2019 07:49

If you know that you want to copy the contents of the window before the window content is generated, then you can use the CLIP command.

For example

Code: Select all

dir | clip
But only the output is captured, not the command itself.

If you want the commands to be included, then put the commands in a batch file with @ECHO ON, and then pipe that result to CLIP.


Dave Benham

Post Reply