June 2018
Intermediate to advanced
398 pages
9h
English
The spawned processes can communicate with the operating system in three channels:
In subprocess, Popen() can interact with the three channels and redirect each stream to an external file, or to a special value called PIPE. An additional method, called communicate(), is used to read from the stdout and write on the stdin. The communicate() method can take input from the user and return both the standard output and the standard error, as shown in the following code snippet:
import subprocessp = subprocess.Popen(["ping", "8.8.8.8", "-c", "3"], stdin=subprocess.PIPE, stdout=subprocess.PIPE)stdout, stderr = p.communicate()print("""==========The ...
Read now
Unlock full access