2 # -*- coding: utf-8 -*-
4 """line_exec.py - Send all lines from stdin to specified programs
6 Reads from stdin and sends every line to the program(s) specified on the
9 File ID: 0a869b50-f45a-11e2-bb76-a088b4ddef28
10 License: GNU General Public License version 2 or later.
17 def exec_line(line
, args
):
19 pipe
= subprocess
.Popen(cmd
, stdin
=subprocess
.PIPE
,
20 stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
)
21 (stdout
, stderr
) = pipe
.communicate(line
)
22 sys
.stdout
.write(stdout
)
24 sys
.stderr
.write(stderr
)
27 def main(args
= None):
28 from optparse
import OptionParser
29 parser
= OptionParser()
30 parser
.add_option("-A", "--after", type="string", dest
="after",
32 help="Text string to add after every line output",
34 parser
.add_option("-B", "--before", type="string", dest
="before",
36 help="Text string to add before every line output",
38 (opt
, args
) = parser
.parse_args()
43 sys
.stdout
.write(opt
.before
)
45 sys
.stdout
.write(opt
.after
)
48 if __name__
== "__main__":