We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 443f417 commit b652330Copy full SHA for b652330
1 file changed
ietf/utils/pipe.py
@@ -0,0 +1,30 @@
1
+# Simplified interface to os.popen3()
2
+
3
+def pipe(cmd, str=None):
4
+ from popen2 import Popen3 as Popen
5
+ bufsize = 4096
6
+ MAX = 65536*16
7
8
+ if str and len(str) > 4096: # XXX: Hardcoded Linux 2.4, 2.6 pipe buffer size
9
+ bufsize = len(str)
10
11
+ pipe = Popen(cmd, True, bufsize)
12
+ if str:
13
+ pipe.tochild.write(str)
14
+ pipe.tochild.close()
15
16
+ out = ""
17
+ err = ""
18
+ while True:
19
+ str = pipe.fromchild.read()
20
21
+ out += str
22
+ code = pipe.poll()
23
+ if code > -1:
24
+ err = pipe.childerr.read()
25
+ break
26
+ if len(out) >= MAX:
27
+ err = "Output exceeds %s bytes and has been truncated"
28
29
30
+ return (code, out, err)
0 commit comments