Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8005143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:08:35+00:00 2026-06-04T17:08:35+00:00

I have a 3rd party console app that prints few lines and immediatelly quits

  • 0

I have a 3rd party console app that prints few lines and immediatelly quits (or waits for a key to be pressed to be closed – depends on used arguments). I would like to run this application from my own console program and get its output into my buffer. I’ve tried this approach but it doesn’t work:

....    
HANDLE stdRead, stdWrite;
SECURITY_ATTRIBUTES PipeSecurity;
ZeroMemory (&PipeSecurity, sizeof (SECURITY_ATTRIBUTES));
PipeSecurity.nLength = sizeof (SECURITY_ATTRIBUTES);
PipeSecurity.bInheritHandle = true;
PipeSecurity.lpSecurityDescriptor = NULL;

CreatePipe (&stdRead, &stdWrite, &PipeSecurity, NULL)

STARTUPINFO sinfo;
ZeroMemory (&sinfo, sizeof (STARTUPINFO));
sinfo.cb = sizeof (STARTUPINFO);
sinfo.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
sinfo.hStdInput = stdWrite;
sinfo.hStdOutput = stdRead;
sinfo.hStdError = stdRead;
sinfo.wShowWindow = SW_SHOW;
CreateProcess (NULL, CommandLine, &PipeSecurity, &PipeSecurity, TRUE, NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE | CREATE_UNICODE_ENVIRONMENT, NULL, NULL, &sinfo, &pi))

DWORD dwRetFromWait= WAIT_TIMEOUT;
while (dwRetFromWait != WAIT_OBJECT_0)
{
    dwRetFromWait = WaitForSingleObject (pi.hProcess, 10);
    if (dwRetFromWait == WAIT_ABANDONED)
        break;

    //--- else (WAIT_OBJECT_0 or WAIT_TIMEOUT) process the pipe data
    while (ReadFromPipeNoWait (stdRead, Buffer, STD_BUFFER_MAX) > 0)
    {
        int iLen= 0; //just for a breakpoint, it never breaks here
    }
}
....


int ReadFromPipeNoWait (HANDLE hPipe, WCHAR *pDest, int nMax)
{
DWORD nBytesRead = 0;
DWORD nAvailBytes;
WCHAR cTmp [10];

ZeroMemory (pDest, nMax * sizeof (WCHAR));
// -- check for something in the pipe
PeekNamedPipe (hPipe, &cTmp, 20, NULL, &nAvailBytes, NULL);
if (nAvailBytes == 0)
    return (nBytesRead); //always ends here + cTmp contains crap

// OK, something there... read it
ReadFile (hPipe, pDest, nMax-1, &nBytesRead, NULL); 

return nBytesRead;
}

If I remove PeekNamedPipe, it just hangs on ReadFile and does nothing. Any ideas what may be wrong? Pipes aren’t unfortunately my cup of tea, I’ve just put together some of the code found on the Internet.

Thanks a lot.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T17:08:36+00:00Added an answer on June 4, 2026 at 5:08 pm

    I’d start with a simple approach:

    char tmp[1024];
    std::string buffer;
    
    FILE *child = _popen("child prog.exe", "r");
    
    if (NULL == child)
        throw std::runtime_error("Unable to spawn child program");
    
    while (fgets(tmp, sizeof(tmp), child))
       buffer += tmp;
    

    Only if you find that doesn’t work, do something more complex to solve the specific problem(s) you encounter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a 3rd party app that does a database export in to a
I have a 3rd Party tool that generates an xml spreadsheet (*.xls). I have
I have a 3rd party JAR that I have converted to an OSGI bundle
I have a 3rd party struct that is comprised of the following: [StructLayout(LayoutKind.Sequential, Size=1)]
I have a 3rd party web page screen capture DLL from http://websitesscreenshot.com/ that lets
We have a 3rd Party Piece of software that I'm wanting to apply some
I have a 3rd-party protocol module (SNMP) that is built on top of asyncore.
I have a 3rd party library that's written in C. It exports all of
We have a DLL that extends a 3rd party application. I would like to
I have a 3rd party JavaScript application that declares several global functions and needs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.