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

A version of the mainpage.html example with stdin #3

Closed
Clodo76 opened this issue Oct 27, 2018 · 1 comment
Closed

A version of the mainpage.html example with stdin #3

Clodo76 opened this issue Oct 27, 2018 · 1 comment

Comments

@Clodo76
Copy link

Clodo76 commented Oct 27, 2018

The example in mainpage.html

const pstreams::pmode mode = pstreams::pstdout|pstreams::pstderr;
ipstream child("echo OUT1; sleep 1; echo ERR >&2; sleep 1; echo OUT2", mode);
char buf[1024];
std::streamsize n;
bool finished[2] = { false, false };
while (!finished[0] || !finished[1])
{
    if (!finished[0])
    {
        while ((n = child.err().readsome(buf, sizeof(buf))) > 0)
            std::cerr.write(buf, n).flush();
        if (child.eof())
        {
            finished[0] = true;
            if (!finished[1])
                child.clear();
        }
    }

    if (!finished[1])
    {
        while ((n = child.out().readsome(buf, sizeof(buf))) > 0)
            std::cout.write(buf, n).flush();
        if (child.eof())
        {
            finished[1] = true;
            if (!finished[0])
                child.clear();
        }
    }
}

Can anyone point me to understand how to change it to write a std::string to stdin before start looping for stdout/stderr output? Thanks.

@Clodo76
Copy link
Author

Clodo76 commented Oct 30, 2018

Resolved with write() and sync(), sorry.

@Clodo76 Clodo76 closed this as completed Oct 30, 2018
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