user2234234
user2234234

Reputation: 349

system calling with arguments and pipe

i have a text in variable called myText, and I want to run command like this:

myText = "This is my text"    
call("echo" + myText + " | mail username -s subj")

it means that I want to echo the text in myText and pass is to mail command thru pipe. what is right way to do this ?

Upvotes: 1

Views: 75

Answers (1)

ibi0tux
ibi0tux

Reputation: 2619

You should have a look to os command such as popen that allows you to create a pipe to make processes communicate between each other. Check out this page

from subprocess import Popen, PIPE
p1 = Popen(['echo', myText], stdout=PIPE)
p2 = Popen('mail', stdin=p1.stdout)

This should work.

Upvotes: 3

Related Questions