Copy text from console window
-
Hi Is there a command to select all text on console window screen? I would like to copy the last screen of text on the console window and save in a text (.scr)file Manually I use Alt + spacebar, E, S to select all and right click the mouse to copy. I run a program in Visual Studio which displays in a console window. Numerous times text is printed to the screen, used and cleared. The last screen of text contains useful information, saved as a script file, and run in a CAD program to draw cabinets and parts. Manual keyboard shortcuts work. A "command" to do the same function would be nice.
Provided you can find the process (which isn't complicated even if you didn't launch it) you can use SendKeys to send the CTRL+A, CTRL+C combination to the console app. AFAIK, there isn't a way to "just read the text" from a generic console window after it has been written there. This may help: https://dzone.com/articles/automatically-send-keys-other[^]
Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!
-
Hi Is there a command to select all text on console window screen? I would like to copy the last screen of text on the console window and save in a text (.scr)file Manually I use Alt + spacebar, E, S to select all and right click the mouse to copy. I run a program in Visual Studio which displays in a console window. Numerous times text is printed to the screen, used and cleared. The last screen of text contains useful information, saved as a script file, and run in a CAD program to draw cabinets and parts. Manual keyboard shortcuts work. A "command" to do the same function would be nice.
Add some smarts to redirect console output as required. [Console.SetOut(TextWriter) Method (System) | Microsoft Docs](https://docs.microsoft.com/en-us/dotnet/api/system.console.setout?view=netframework-4.8) Note that you can then read your own console output if need be (if you redirect to a file).
The Master said, 'Am I indeed possessed of knowledge? I am not knowing. But if a mean person, who appears quite empty-like, ask anything of me, I set it forth from one end to the other, and exhaust it.' ― Confucian Analects
-
Hi Is there a command to select all text on console window screen? I would like to copy the last screen of text on the console window and save in a text (.scr)file Manually I use Alt + spacebar, E, S to select all and right click the mouse to copy. I run a program in Visual Studio which displays in a console window. Numerous times text is printed to the screen, used and cleared. The last screen of text contains useful information, saved as a script file, and run in a CAD program to draw cabinets and parts. Manual keyboard shortcuts work. A "command" to do the same function would be nice.
`CTRL-A` is supposed to select all text in a control or context in Windows. However, it doesn't seem to work in either the PowerShell window or Windows Terminal. I would be very curious about a solution as well.
-
`CTRL-A` is supposed to select all text in a control or context in Windows. However, it doesn't seem to work in either the PowerShell window or Windows Terminal. I would be very curious about a solution as well.
-
Hi Is there a command to select all text on console window screen? I would like to copy the last screen of text on the console window and save in a text (.scr)file Manually I use Alt + spacebar, E, S to select all and right click the mouse to copy. I run a program in Visual Studio which displays in a console window. Numerous times text is printed to the screen, used and cleared. The last screen of text contains useful information, saved as a script file, and run in a CAD program to draw cabinets and parts. Manual keyboard shortcuts work. A "command" to do the same function would be nice.
Wow you guys are fast. This is my own program. I can look into using SendKey and TextWriter. I might use TextWriter when I start to write the last screen of text or possibly SendKey when the last screen is printed. Sure appreciate it. for console window, to select all, first set up your properties Alt + spacebar (shows the dropdown menu) P (to choose Properties) Options tab- check Quick Edit Mode and Insert Mode Alt + spacebar, E (for Edit), S (for Select All) right click mouse (to copy to clipboard) If you want to paste at command prompt- copy the command- in console window, right click to paste at command prompt. Again, thanks
-
Wow you guys are fast. This is my own program. I can look into using SendKey and TextWriter. I might use TextWriter when I start to write the last screen of text or possibly SendKey when the last screen is printed. Sure appreciate it. for console window, to select all, first set up your properties Alt + spacebar (shows the dropdown menu) P (to choose Properties) Options tab- check Quick Edit Mode and Insert Mode Alt + spacebar, E (for Edit), S (for Select All) right click mouse (to copy to clipboard) If you want to paste at command prompt- copy the command- in console window, right click to paste at command prompt. Again, thanks
-
CTRL-A is commonly used to select all text, but it must be implemented by the application itself. It works fine in a cmd window, but powershell ISE/console seems not to work.
Just did an experiment. I opened CMD.exe and CTRL-A worked. Then I typed powershell.exe and powershell opened in the CMD.exe window. CTRL-A no longer works. Exit powershell to CMD.exe and CTRL-A works again. So PowerShell is eating CTRL-A and not doing anything with it.
-
Wow you guys are fast. This is my own program. I can look into using SendKey and TextWriter. I might use TextWriter when I start to write the last screen of text or possibly SendKey when the last screen is printed. Sure appreciate it. for console window, to select all, first set up your properties Alt + spacebar (shows the dropdown menu) P (to choose Properties) Options tab- check Quick Edit Mode and Insert Mode Alt + spacebar, E (for Edit), S (for Select All) right click mouse (to copy to clipboard) If you want to paste at command prompt- copy the command- in console window, right click to paste at command prompt. Again, thanks
Is the console window part of your own app or is it an external to your app?
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak -
Just did an experiment. I opened CMD.exe and CTRL-A worked. Then I typed powershell.exe and powershell opened in the CMD.exe window. CTRL-A no longer works. Exit powershell to CMD.exe and CTRL-A works again. So PowerShell is eating CTRL-A and not doing anything with it.
The reverse also applies - open Powershell, Ctrl+A doesn't work; run
cmd.exe
, and Ctrl+A works; exit back to Powershell, and it stops working again. I haven't tried in the new Windows Terminal[^] to see if it's been fixed.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Is the console window part of your own app or is it an external to your app?
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak -
I wrote a program in C# that runs in Visual Studio as a console application. When I run the program, in debug, it runs in a console window.
OK, so then why are you trying to copy'n'paste your own window text? You're going to have to rethink your code and write a module that can write the required text to both the console window and to the file you want to capture the data to.
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak -
OK, so then why are you trying to copy'n'paste your own window text? You're going to have to rethink your code and write a module that can write the required text to both the console window and to the file you want to capture the data to.
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave KreskowiakI change over to using StreamWriter. I have used it before, I wasn't thinking.
using System.IO;
using (StreamWriter list = new StreamWriter("C:\\Users\\Gene\\Desktop\\Test.scr", true)) {list.WriteLine("Line " + cabinetx + "," + topy + " @" + cabinetWidth + ",0\\n");
}
I changed from Console.WriteLine( ) to list.WriteLine( )
Works great. Beautiful thing. It doesn't print to screen but it does write to a text file.I use progeCad. (similar to AutoCad)
I saw this online. Running script in Cad program
It draws a 1" square box. And it did it all in 1 line of code.Line 0,0 @1,0 @0,1 @-1,0 close
Starts a line command. Space is like hitting the spacebar or Enter key.
Where do you want to start from? x,y coordinate 0,0. Space
What's the next point? @1,0. Space. and so forthAfter that, I drew a cabinet, used it as a model to gather locations and sizes of Left end, right end, top, deck and measured for precise locations and sizes.
From those measurements I typed out these commandsRectangle 0,4 @0.75,30.5
Rectangle 30,4 @-0.75,30.5
Rectangle 0.75,34.5 @28.5,-0.75
Rectangle 0.75,4 @28.5,0.75Saved as a script file (.scr) and ran in progeCad as script file
It drew out in a split second what I had drawn previously for a model
After that, it was like candy. What other parts can I draw?The program is two parts
First part gathers information- width, height, depth. Top drawer and 1 door, with 2 adjustable shelves. This is done thru user input, to change location, sizes and choice of parts.
Numerous windows display, allowing changes. Window is cleared and the next window is diplayed...Second part is where all the commands code is generated. (similar to lines of code above)
I copy the command codes, paste in a text file, save as script file and run in progecad
Each line, represents one full command in progeCad. The first line runs and jumps to the next line until the end. It just drew several views of the cabinet.Using StreamWriter, no more copy and pasting.
Thanks again. -
I change over to using StreamWriter. I have used it before, I wasn't thinking.
using System.IO;
using (StreamWriter list = new StreamWriter("C:\\Users\\Gene\\Desktop\\Test.scr", true)) {list.WriteLine("Line " + cabinetx + "," + topy + " @" + cabinetWidth + ",0\\n");
}
I changed from Console.WriteLine( ) to list.WriteLine( )
Works great. Beautiful thing. It doesn't print to screen but it does write to a text file.I use progeCad. (similar to AutoCad)
I saw this online. Running script in Cad program
It draws a 1" square box. And it did it all in 1 line of code.Line 0,0 @1,0 @0,1 @-1,0 close
Starts a line command. Space is like hitting the spacebar or Enter key.
Where do you want to start from? x,y coordinate 0,0. Space
What's the next point? @1,0. Space. and so forthAfter that, I drew a cabinet, used it as a model to gather locations and sizes of Left end, right end, top, deck and measured for precise locations and sizes.
From those measurements I typed out these commandsRectangle 0,4 @0.75,30.5
Rectangle 30,4 @-0.75,30.5
Rectangle 0.75,34.5 @28.5,-0.75
Rectangle 0.75,4 @28.5,0.75Saved as a script file (.scr) and ran in progeCad as script file
It drew out in a split second what I had drawn previously for a model
After that, it was like candy. What other parts can I draw?The program is two parts
First part gathers information- width, height, depth. Top drawer and 1 door, with 2 adjustable shelves. This is done thru user input, to change location, sizes and choice of parts.
Numerous windows display, allowing changes. Window is cleared and the next window is diplayed...Second part is where all the commands code is generated. (similar to lines of code above)
I copy the command codes, paste in a text file, save as script file and run in progecad
Each line, represents one full command in progeCad. The first line runs and jumps to the next line until the end. It just drew several views of the cabinet.Using StreamWriter, no more copy and pasting.
Thanks again.OK, so what's wrong with adding a Console.Write immediately after your write to the file?
using (StreamWriter list = new StreamWriter("C:\\Users\\Gene\\Desktop\\Test.scr", true)) {
string content = "Line " + cabinetx + "," + topy + " @" + cabinetWidth + ",0\n";
list.WriteLine(content);
Console.Write(content);
}Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak -
OK, so then why are you trying to copy'n'paste your own window text? You're going to have to rethink your code and write a module that can write the required text to both the console window and to the file you want to capture the data to.
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave KreskowiakI need to save the text that comes up on the last screen displayed. It's the whole purpose of the program, to generate the text displayed on the last screen. I don't need to see it. I do need to copy and paste it. Before, I have printed the text to the last screen for one reason. To select all- and copy to clipboard then to paste and save in a text document. I needed it displayed so I could copy it. Now, using StreamWriter, that information is written to a text file and saved I no longer have to copy and paste. I don't need to see it. And if I want to see the text from the last page, I can open the text file. It's an exact copy There are several hundred lines I need to change from Console.WriteLine to list.Writeline I have changed several methods that are writing to the text file. It's working as expected. Thanks