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 918625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:24:26+00:00 2026-05-15T18:24:26+00:00

So I keep bouncing between named and anonymous pipes and here is my issue.

  • 0

So I keep bouncing between named and anonymous pipes and here is my issue. I tried named pipes and they just didn’t seem to work properly for what I wanted, so I’m back to anonymous pipes. However, the anonymous pipe needs to read input from a pipe (to a program that I did not create) and continuously read it as more information is available to the pipe. Here is the relevant code which I currently have:

void Arc_Redirect::createProcesses()
{
    TCHAR programName[]=TEXT("program.exe");
    PROCESS_INFORMATION pi; 
    STARTUPINFO si;

    SECURITY_ATTRIBUTES sa;
    sa.nLength = sizeof(SECURITY_ATTRIBUTES);
    sa.bInheritHandle = TRUE;
    sa.lpSecurityDescriptor = NULL;

    if(!CreatePipe(&outStd[0].hOutRead,&outStd[0].hOutWrite,&sa,0) || !CreatePipe(&outStd[0].hInRead,&outStd[0].hInWrite,&sa,0))
        throw "Error: Could not CreatePipe();!";

    if(!SetHandleInformation(outStd[0].hOutRead,HANDLE_FLAG_INHERIT,0) || !SetHandleInformation(outStd[0].hInWrite,HANDLE_FLAG_INHERIT,0))
        throw "Error: Could not SetHandleInformation();";


    // Set stuff up
    ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
    ZeroMemory(&si, sizeof(STARTUPINFO));
    si.cb = sizeof(STARTUPINFO); 
    si.hStdError = outStd[0].hOutWrite;
    si.hStdOutput = outStd[0].hOutWrite;
    si.hStdInput = outStd[0].hInRead;
    si.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;

    outStd[0].o1.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);

    if(!CreateProcess(programName,NULL,NULL,NULL,TRUE,0,NULL,NULL,&si,&pi))
        throw "Error: Could not start Program!";

    // Cleanup the useless handles
    if(!CloseHandle(pi.hThread) || !CloseHandle(pi.hProcess))
        throw "Error: Could not CloseHandle();";
}

And here is how I am reading the pipe:

void Arc_Redirect::readPipe()
{
    CHAR chBuf[BUFSIZE];
    DWORD dwRead;

    ReadFile(outStd[0].hOutRead,chBuf,sizeof(chBuf),&dwRead,&outStd[0].o1);
    chBuf[dwRead] = '\0';
    SetDlgItemText(global,IDO_WORLDOUT,chBuf);
    ResetEvent(outStd[0].o1.hEvent);

}

BUFSIZE is defined at 0x1000 and outStd is defined as PIPE_HANDLES (struct below)

typedef struct
{
    HANDLE hOutRead;
    HANDLE hOutWrite;
    HANDLE hInRead;
    HANDLE hInWrite;
    OVERLAPPED o1;
    TCHAR chReq[BUFSIZE];
    TCHAR chReply[BUFSIZE];
    DWORD dwRead;
    DWORD dwWritten;
    DWORD dwState;
    DWORD cbRet;
    BOOL pendingIO;
} PIPE_HANDLES, *LPSTDPIPE;

Now, I can properly call readPipe(); once and it does exactly what I want. However, if I try to call it again, it fails. Any ideas on how I can fix this issue? Like I said, I need to keep the connection open and read incrementally. For sake of argument, say I need to read every 5 secs; the program I am reading from will have different output every 5 secs that needs to be read. Any help?

Regards,
Dennis M.

  • 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-05-15T18:24:27+00:00Added an answer on May 15, 2026 at 6:24 pm

    It is impossible to guess why it fails if you don’t find out why. ReadFile returns FALSE when it fails. You should then call GetLastError() to get a diagnostic.

    Never ignore Windows API return values. At the very least assert them.

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

Sidebar

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.