Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1306
  • Last Modified:

How do I redirect console output from cmd.exe for full-screen console apps

How do I redirect console output from cmd.exe for full-screen console apps, e.g. telnet, edit, etc. I wish to gain access to application input & output.

I'm assuming that either the program (e.g. telnet) or the shell (e.g. cmd.exe) is making calls to the windows console functions, e.g. ReadConsoleOutput, WriteConsoleInput, etc. These functions fail when the STDIN, STDOUT and STDERR streams have been redirected. Does anyone know of code to get and redirect the info? Is it a matter of hooking all the console functions in user32.dll or kernel32.dll?

Thanks for any info.
0
geriatrix
Asked:
geriatrix
  • 3
2 Solutions
 
geriatrixAuthor Commented:
OK, platform is PC, OS = Windows XP/Vista, language = {VB.NET, C/C++, C#}. Related applications: maybe powershell.
0
 
abelCommented:
The angle of this article is slightly different, but what is of interest for you is the SpawnDumpConsole function. The code is in C++ but it comes with full source code: http://www.codeproject.com/KB/dialog/ConsoleAdapter.aspx
0
 
abelCommented:
Alternatively, though I did not try this myself, this article provides you insightful information (six pages) about the inner workings and how you can deal with them from code: http://www.devsource.com/c/a/Using-VS/Working-with-Console-Screen-Buffers-in-NET/1/
0
 
abelCommented:
I showed a link with a solution. This particular question is quite hard to solve, but on the locations of these links is enough information, including full solutions. I don't think this question should be deleted (I already had it in my KB for that matter...)
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now