Bram Moolenaar | 6463ca2 | 2016-02-13 17:04:46 +0100 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | # |
| 3 | # Server that will communicate over stdin/stderr |
| 4 | # |
| 5 | # This requires Python 2.6 or later. |
| 6 | |
| 7 | from __future__ import print_function |
| 8 | import sys |
Bram Moolenaar | bbe8d91 | 2016-06-05 16:10:57 +0200 | [diff] [blame] | 9 | import time |
Bram Moolenaar | 6463ca2 | 2016-02-13 17:04:46 +0100 | [diff] [blame] | 10 | |
| 11 | if __name__ == "__main__": |
| 12 | |
| 13 | if len(sys.argv) > 1: |
Bram Moolenaar | f65333c | 2016-03-08 18:27:21 +0100 | [diff] [blame] | 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() |
Bram Moolenaar | b2658a1 | 2016-04-26 17:16:24 +0200 | [diff] [blame] | 20 | if sys.argv[1].startswith("quit"): |
| 21 | sys.exit(0) |
Bram Moolenaar | 6463ca2 | 2016-02-13 17:04:46 +0100 | [diff] [blame] | 22 | |
| 23 | while True: |
| 24 | typed = sys.stdin.readline() |
| 25 | if typed.startswith("quit"): |
| 26 | print("Goodbye!") |
| 27 | sys.stdout.flush() |
| 28 | break |
Bram Moolenaar | c25558b | 2016-03-03 21:02:23 +0100 | [diff] [blame] | 29 | if typed.startswith("echo "): |
Bram Moolenaar | 6463ca2 | 2016-02-13 17:04:46 +0100 | [diff] [blame] | 30 | print(typed[5:-1]) |
| 31 | sys.stdout.flush() |
Bram Moolenaar | e98d121 | 2016-03-08 15:37:41 +0100 | [diff] [blame] | 32 | if typed.startswith("double "): |
Bram Moolenaar | 9a6e33a | 2016-02-16 19:25:12 +0100 | [diff] [blame] | 33 | print(typed[7:-1] + "\nAND " + typed[7:-1]) |
| 34 | sys.stdout.flush() |
Bram Moolenaar | bbe8d91 | 2016-06-05 16:10:57 +0200 | [diff] [blame] | 35 | if typed.startswith("split "): |
| 36 | print(typed[6:-1], end='') |
| 37 | sys.stdout.flush() |
| 38 | time.sleep(0.05) |
| 39 | print(typed[6:-1], end='') |
| 40 | sys.stdout.flush() |
| 41 | time.sleep(0.05) |
| 42 | print(typed[6:-1]) |
| 43 | sys.stdout.flush() |
Bram Moolenaar | e98d121 | 2016-03-08 15:37:41 +0100 | [diff] [blame] | 44 | if typed.startswith("echoerr "): |
| 45 | print(typed[8:-1], file=sys.stderr) |
| 46 | sys.stderr.flush() |
| 47 | if typed.startswith("doubleerr "): |
| 48 | print(typed[10:-1] + "\nAND " + typed[10:-1], file=sys.stderr) |
| 49 | sys.stderr.flush() |
Bram Moolenaar | 6463ca2 | 2016-02-13 17:04:46 +0100 | [diff] [blame] | 50 | |