1#!/usr/bin/python 2# 3# Server that will communicate over stdin/stderr 4# 5# This requires Python 2.6 or later. 6 7from __future__ import print_function 8import sys 9import time 10 11if __name__ == "__main__": 12 13 if len(sys.argv) > 1: 14 if sys.argv[1].startswith("err"): 15 print(sys.argv[1], file=sys.stderr) 16 sys.stderr.flush() 17 else: 18 print(sys.argv[1]) 19 sys.stdout.flush() 20 if sys.argv[1].startswith("quit"): 21 sys.exit(0) 22 23 while True: 24 typed = sys.stdin.readline() 25 if typed.startswith("quit"): 26 print("Goodbye!") 27 sys.stdout.flush() 28 break 29 if typed.startswith("echo "): 30 print(typed[5:-1]) 31 sys.stdout.flush() 32 if typed.startswith("echosplit "): 33 for part in typed[10:-1].split('|'): 34 sys.stdout.write(part) 35 sys.stdout.flush() 36 time.sleep(0.05) 37 if typed.startswith("double "): 38 print(typed[7:-1] + "\nAND " + typed[7:-1]) 39 sys.stdout.flush() 40 if typed.startswith("split "): 41 print(typed[6:-1], end='') 42 sys.stdout.flush() 43 time.sleep(0.05) 44 print(typed[6:-1], end='') 45 sys.stdout.flush() 46 time.sleep(0.05) 47 print(typed[6:-1]) 48 sys.stdout.flush() 49 if typed.startswith("echoerr "): 50 print(typed[8:-1], file=sys.stderr) 51 sys.stderr.flush() 52 if typed.startswith("doubleerr "): 53 print(typed[10:-1] + "\nAND " + typed[10:-1], file=sys.stderr) 54 sys.stderr.flush() 55 56