Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How do I get the error message displayed on a console ?

How do I get the error message displayed on a console ?

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SherTeks
    wrote on last edited by
    #1

    I've a third-party console application 'MyTestConsole.exe' that I launch by CreateProcess.

    STARTUPINFO StartUpInfo;
    PROCESS_INFORMATION ProcInfo;

    memset(&StartUpInfo, 0, sizeof(StartUpInfo));
    memset(&ProcInfo, 0, sizeof(ProcInfo));

    StartUpInfo.dwFlags = STARTF_USESHOWWINDOW;
    // StartUpInfo.wShowWindow = SW_HIDE;
    StartUpInfo.wShowWindow = SW_SHOWNORMAL;

    CreateProcess( "D:\\MyTestConsole.exe", NULL, NULL, NULL, NULL, CREATE_NEW_CONSOLE, NULL, NULL, &StartUpInfo, &ProcInfo);

    The console application launches successfully, but displays a standard windows error message, say for instance 'Error : could not open file' Now, how do I get the error string 'Error : could not open file' in a CString object. May be I'll have to use AttachConsole() and other console functions but not sure how. Pleae give your suggestions. Thanks in advance.

    S N 2 Replies Last reply
    0
    • S SherTeks

      I've a third-party console application 'MyTestConsole.exe' that I launch by CreateProcess.

      STARTUPINFO StartUpInfo;
      PROCESS_INFORMATION ProcInfo;

      memset(&StartUpInfo, 0, sizeof(StartUpInfo));
      memset(&ProcInfo, 0, sizeof(ProcInfo));

      StartUpInfo.dwFlags = STARTF_USESHOWWINDOW;
      // StartUpInfo.wShowWindow = SW_HIDE;
      StartUpInfo.wShowWindow = SW_SHOWNORMAL;

      CreateProcess( "D:\\MyTestConsole.exe", NULL, NULL, NULL, NULL, CREATE_NEW_CONSOLE, NULL, NULL, &StartUpInfo, &ProcInfo);

      The console application launches successfully, but displays a standard windows error message, say for instance 'Error : could not open file' Now, how do I get the error string 'Error : could not open file' in a CString object. May be I'll have to use AttachConsole() and other console functions but not sure how. Pleae give your suggestions. Thanks in advance.

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      This example[^] shows how to use a pipe to capture output from a child process - that's what you're wanting to do. To summarise what the example does:

      1. Create a pipe to capture the child processes standard output and error streams (that's the console output).
      2. Make sure the current processes standard handles aren't inheritable
      3. Use the lpStartupInfo parameter to CreateProcess to specify the pipe as the child processes standard stream handles
      4. Keep reading the pipe attached to the child's standard output until it's closed

      HTH!

      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

      1 Reply Last reply
      0
      • S SherTeks

        I've a third-party console application 'MyTestConsole.exe' that I launch by CreateProcess.

        STARTUPINFO StartUpInfo;
        PROCESS_INFORMATION ProcInfo;

        memset(&StartUpInfo, 0, sizeof(StartUpInfo));
        memset(&ProcInfo, 0, sizeof(ProcInfo));

        StartUpInfo.dwFlags = STARTF_USESHOWWINDOW;
        // StartUpInfo.wShowWindow = SW_HIDE;
        StartUpInfo.wShowWindow = SW_SHOWNORMAL;

        CreateProcess( "D:\\MyTestConsole.exe", NULL, NULL, NULL, NULL, CREATE_NEW_CONSOLE, NULL, NULL, &StartUpInfo, &ProcInfo);

        The console application launches successfully, but displays a standard windows error message, say for instance 'Error : could not open file' Now, how do I get the error string 'Error : could not open file' in a CString object. May be I'll have to use AttachConsole() and other console functions but not sure how. Pleae give your suggestions. Thanks in advance.

        N Offline
        N Offline
        Naveen
        wrote on last edited by
        #3

        Check the following article for information about redirecting output.... http://www.codeproject.com/KB/dialog/ConsoleAdapter.aspx[^]

        nave [OpenedFileFinder] [My Blog]

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups