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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:54:50+00:00 2026-06-14T20:54:50+00:00

How do I passively listen to stderr and obtain it as string for sending

  • 0

How do I passively listen to stderr and obtain it as string for sending to callback? I have seen posts on reading stderr but I want to listen to it rather than actively reading it.

Background:
I have a cross-platform piece that uses 3rd party library (libcurl) which will output verbose info into stderr. This cross-platform piece is to be used by more than 1 non-cross-platform applications.

I would like to log these info, which I can do by providing FILE* to libcurl. But instead of doing that, I want to see if I can capture (passively listen to) the output in stderr as string, and send back to the calling main application via callback. This has the benefit of 1. main app can keep a single log using whatever logging tool it wants. 2. it will keep this piece cross-platform.

  • 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-14T20:54:51+00:00Added an answer on June 14, 2026 at 8:54 pm

    Doing this in a single process is a little tricky, but you can probably do it.

    • 1: Using freopen() you can redirect your stderr to a named file. You can simultaneously open that file for reading on another handle. You might also need to call setvbuf() on stderr to turn off buffering on output to stderr so that you will be able to read it right away from the 2nd handle. Since it is being written to a file you can read it at anytime – when it is convenient. The unix function “select” is what you need if you want to be notified when the file changes. (see also fileno()).

    • 2: More tricky would be to setup stderr as the write end of a pipe. Should be doable using dup3(), though this isn’t exactly cross-platform (to non-unixy OS’s). It would also require that a 2nd thread be reading from the pipe to prevent the writer from being blocked if they write very much.

    Like:

    FILE *stream = freopen("stderr.out", "w", stderr); // Added missing pointer
    setvbuf(stream, 0, _IONBF, 0); // No Buffering
    FILE *input = fopen("stderr.out", "r");
    fprintf(stderr, "Output to stderr dude\n");
    //fflush(stderr); // You can explicitly flush instead of setting no buffering.
    char buffer[1024];
    while (fgets(buffer, 512, input))
    {
        printf(">>>%s\n", buffer);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have traditionally implemented a Model-View-Presenter [Passive View] like so: interface IView { string
this is probably trivial but I need help in making my server listen on
I have code (my c++ socket server) but I don't know How can I
HI Gurus, I'm looking to replace an IN clause with exists, but despite reading
I am either massively tired or really confused... But I'm not sure... I have
I have zero javascript experience but have a task which I believe can be
I'm rather new with Regular Expressions in general. Basically, I want to rewrite a
We've made a library which uses massively (with inheritance) numpy's MaskedArrays. But I want
I am writing a massively parallel GPU application using CUDA. I have been optimizing
I'm not massively familiar with this design but I am hoping to get some

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.