A
A
ametko2018-08-02 01:57:59
Python
ametko, 2018-08-02 01:57:59

How to return value from child process to parent?

It is necessary to launch the child script from the parent script and transfer information there, preferably using the subprocess library, then the child script must process it and return it to the parent script. How can I get it back through Pipe?
This is what the child process looks like
proc = Popen(
[sys.executable, "h.py"],
shell=True,
stdout=PIPE, stderr=PIPE
)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2018-08-02
@ametko

Parent

from subprocess import Popen, PIPE

process = Popen(["python", "child.py"], stdout=PIPE, stdin=PIPE, shell=True)
print(process.communicate(b"Hello!")[0].decode())
print(process.wait())

user = input()
if user == "Hello!":
    print("Hello user!")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question