M
M
Marat Nagayev2021-07-13 23:03:40
linux
Marat Nagayev, 2021-07-13 23:03:40

How to read from stdout of another process in linux api?

There is the following code on WinApi:

std::string getResponseFromEngine(position)
{
    WriteFile(pipin_w, position.c_str(), position.length(),&writ, NULL);
    Sleep(500);
    PeekNamedPipe(pipout_r, buffer,sizeof(buffer), &read, &available, NULL);   
    do
    {   
        ZeroMemory(buffer, sizeof(buffer));
        if(!ReadFile(pipout_r, buffer, sizeof(buffer), &read, NULL) || !read) break; 
        buffer[read] = 0;    
        str+=(char*)buffer;
    }
    while(read >= sizeof(buffer));
    return str;
}

How can it be replaced by analogues in linux api?
The situation is as follows: there is a running application and it is necessary to send information to its stdin and read from stdout.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stanislav Makarov, 2021-07-13
@Nipheris

Capture the output of a child process in C
I think the same can be done for stdin.

R
res2001, 2021-07-14
@res2001

In Linux, there are named and unnamed pipes in the same way, the API, of course, is different, but the essence does not change.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question