Skip to content

I can send() but I have no way of closing the input channel #21

@mohamedAlaaK

Description

@mohamedAlaaK
#include <subprocess.hpp>

using namespace std;
using namespace subprocess;

int main()
{
	vector<Popen> sub_processes;
	for ( int i = 0 ; i < 5 ; i++ )
	{
		sub_processes.emplace_back(Popen({"cat"},input{PIPE}));
		sub_processes[i].send("3 5\n", 5);
	}

	for ( int i = 0 ; i < 5 ; i++ )
	{
		sub_processes[i].wait(); // waits forever
	}
}

In the code above I spawn 5 instances of cat. I call send() to each of them.
In the second loop we call wait but it waits forever. I suspect that cat is still waiting for more input because the channel was not closed.

communicate() does close the channels. But I need to use send() is there a function I am missing that can close the channels?

Thanks in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions