0 votes
in Python by
What is the process to run sub-process with pipes that connect both input and output?

1 Answer

0 votes
by

The popen2() module is used to run the sub-process but due to some difficulty in processing like creation of deadlock keeping a process blocked and waiting for the output from the child and child is waiting for the input. The deadlock occurs due to the fact that parent and child doesn’t have the synchronization and both are waiting to get the processor to provide the resources to one another. Use of popen3() method allows the reading of stdout and stderr to take place where the internal buffer increases and there is no read() takes place to share the resources. popen2() takes care of the deadlock by providing the methods like wait() and waitpid() that finish a process first and when a request comes, it hands over the responsibility to the process waiting for the resources.

The program is used to show the process and run it.

import popen2

fromchild, tochild = popen2.popen2("command")

tochild.write("input\n")

tochild.flush()

output = fromchild.readline()

Related questions

0 votes
asked Aug 22, 2022 in Python by Robindeniel
0 votes
asked Aug 22, 2022 in Python by Robindeniel
...