Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asynchronous Pipe Read #24

Open
starlight-traveler opened this issue Sep 5, 2024 · 0 comments
Open

Asynchronous Pipe Read #24

starlight-traveler opened this issue Sep 5, 2024 · 0 comments

Comments

@starlight-traveler
Copy link

starlight-traveler commented Sep 5, 2024

Hello!

This may be more of a feature request or simply an implementation issue that I am not following, however is there support for asynchronous pipe reads, for instance can I read every line that comes in from the buffer instead of waiting for the execution of the program to complete.

void rnsd_dameon(quill::Logger *logger)
{
    // Start the rnsd subprocess with output piped
    Popen popen = RunBuilder({"rnsd"})
                      .cout(PipeOption::pipe)
                      .popen();

    // Buffer to store the output
    char buf[1024];

    // Read from the output pipe until there's no more data
    size_t bytes_read = 0;
    while ((bytes_read = subprocess::pipe_read(popen.cout, buf, sizeof(buf) - 1)) > 0)
    {
        buf[bytes_read] = '\0';           // Null-terminate the string
        LOG_INFO(logger, "RNSD: {}", buf); 
        std::memset(buf, 0, sizeof(buf)); // Clear the buffer
    }

    // // Close the process and handle cleanup
    // popen.close();
}

For instance rnsd is a subprocess that outputs logging information, however only when I force terminate the program will we see anything output to stdrr. Is this simply a limitation of the library or am I missing something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant