blob: 639cc6c2669713a5bd41bc3f7a1406de6a7472e1 [file] [log] [blame]
Bram Moolenaar6463ca22016-02-13 17:04:46 +01001#!/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
Bram Moolenaarbbe8d912016-06-05 16:10:57 +02009import time
Bram Moolenaar6463ca22016-02-13 17:04:46 +010010
11if __name__ == "__main__":
12
13 if len(sys.argv) > 1:
Bram Moolenaarf65333c2016-03-08 18:27:21 +010014 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 Moolenaarb2658a12016-04-26 17:16:24 +020020 if sys.argv[1].startswith("quit"):
21 sys.exit(0)
Bram Moolenaar6463ca22016-02-13 17:04:46 +010022
23 while True:
24 typed = sys.stdin.readline()
25 if typed.startswith("quit"):
26 print("Goodbye!")
27 sys.stdout.flush()
28 break
Bram Moolenaarc25558b2016-03-03 21:02:23 +010029 if typed.startswith("echo "):
Bram Moolenaar6463ca22016-02-13 17:04:46 +010030 print(typed[5:-1])
31 sys.stdout.flush()
Bram Moolenaare98d1212016-03-08 15:37:41 +010032 if typed.startswith("double "):
Bram Moolenaar9a6e33a2016-02-16 19:25:12 +010033 print(typed[7:-1] + "\nAND " + typed[7:-1])
34 sys.stdout.flush()
Bram Moolenaarbbe8d912016-06-05 16:10:57 +020035 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 Moolenaare98d1212016-03-08 15:37:41 +010044 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 Moolenaar6463ca22016-02-13 17:04:46 +010050