Last active
August 29, 2015 14:09
-
-
Save cmouse/7e9a686db22879678345 to your computer and use it in GitHub Desktop.
Subprocess issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io,re,unittest,os,json,sys | |
from subprocess import PIPE, STDOUT, Popen | |
sub = Popen(["/usr/bin/python3.4", "test2.py", "pipe"], stdin=PIPE, stdout=PIPE, stderr=sys.stderr, close_fds=True, shell=False) | |
(writer,reader) = (sub.stdin, sub.stdout) | |
writer.write("HELO\t1\n".encode("utf-8")) | |
writer.flush() | |
sub.poll() | |
line = reader.readline().decode("utf-8") | |
assert(re.match("^OK\t", line)) | |
writer.write("Q\ttest.com\tIN\tSOA\t-1\t127.0.0.1\n".encode("utf-8")) | |
line = reader.readline().decode("utf-8") | |
assert(re.match("^DATA\ttest.com\tIN\tSOA\t300\t-1\tsns.dns.icann.org. noc.dns.icann.org. 2013073082 7200 3600 1209600 3600", line)) | |
sub.stdout.close() | |
sub.stdin.close() | |
sub.kill() | |
sub.wait() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
sys.stderr.write(sys.stdin.readline()) | |
sys.stdout.write("OK\tversion foo bar hello\n") | |
sys.stdout.flush() | |
sys.stderr.write(sys.stdin.readline()) | |
sys.stdout.write("DATA\ttest.com\tIN\tSOA\t300\t-1\tsns.dns.icann.org. noc.dns.icann.org. 2013073082 7200 3600 1209600 3600") | |
sys.stdout.flush() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment