- self.p = subprocess.Popen(name, stdin=subprocess.PIPE, stdout=subprocess.PIPE,stderr=sys.stderr)
- try:
- self.p.stdin.write(colour + "\n")
- except:
+ self.p = subprocess.Popen(name, stdin=subprocess.PIPE, stdout=subprocess.PIPE,stderr=subprocess.PIPE)
+
+ self.send_message(colour)
+
+ def send_message(self, s):
+ if agent_timeout > 0.0:
+ ready = select.select([], [self.p.stdin], [], agent_timeout)[1]
+ else:
+ ready = [self.p.stdin]
+ if self.p.stdin in ready:
+ #print "Writing to p.stdin"
+ try:
+ self.p.stdin.write(s + "\n")
+ except:
+ raise Exception("UNRESPONSIVE")
+ else:
+ raise Exception("UNRESPONSIVE")
+
+ def get_response(self):
+ if agent_timeout > 0.0:
+ ready = select.select([self.p.stdout], [], [], agent_timeout)[0]
+ else:
+ ready = [self.p.stdout]
+ if self.p.stdout in ready:
+ #print "Reading from p.stdout"
+ try:
+ return self.p.stdout.readline().strip("\r\n")
+ except: # Exception, e:
+ raise Exception("UNRESPONSIVE")
+ else: