Thread: Getting output from console apps

  1. #1
    Registered User
    Join Date
    Aug 2001
    Location
    Melbourne, Australia
    Posts
    92

    Unhappy Getting output from console apps

    Some products, such as MSVC++ can capture the output from an application they run (ie. a compiler).

    I want to do this, to create a sort of "windows console" - simmilar to consoles found in games, but a convinent way of using the command prompt without having to load it up all the time.

    So my problem is: How do I capture the output of a console app, or system command (like dir, cd, mkdir etc...)

    Thanks!!

    Jeff
    psychobrat at gmail

  2. #2
    Registered User
    Join Date
    Oct 2002
    Posts
    5
    Check MSDN for the following functions:

    AllocConsole
    GetStdHandle
    ReadConsole
    WriteConsole
    FreeConsole

  3. #3
    Registered User
    Join Date
    Aug 2001
    Location
    Melbourne, Australia
    Posts
    92

    Smile

    Ok, now I have the following in my app:

    Code:
    AllocConsole();
    char foostring[] = "dir";
    system(foostring);
    Which outputs the return of a "dir" command into my new console. Now how do I make it instead of outputting that to the console window, put it into my own buffer?

    Thanks again,
    Jeff
    psychobrat at gmail

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Some compilers have popen() or _popen() which will open a pipe to a command. You might try searching your documentation for such things.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to get the console output
    By outlawbt in forum Windows Programming
    Replies: 2
    Last Post: 03-19-2008, 02:25 PM
  2. redirect console output to a String?
    By TwistedMetal in forum C Programming
    Replies: 10
    Last Post: 02-26-2008, 02:54 PM
  3. Help with Console output
    By JeremyCAFE in forum C++ Programming
    Replies: 4
    Last Post: 12-20-2005, 10:36 AM
  4. Redirecting console output
    By _hannes in forum Windows Programming
    Replies: 3
    Last Post: 11-04-2004, 04:51 AM
  5. graphics in c/c++ console apps
    By anthonye in forum C Programming
    Replies: 2
    Last Post: 06-20-2002, 05:39 AM