import subprocess # Some text to send text = b''' hello world this is a test goodbye ''' # Launch a command with pipes p = subprocess.Popen(['wc'], stdout = subprocess.PIPE, stdin = subprocess.PIPE) # Send the data and get the output stdout, stderr = p.communicate(text) text = stdout.decode('utf-8') print(text)