-
Notifications
You must be signed in to change notification settings - Fork 0
/
time2CSharp.py
41 lines (34 loc) · 879 Bytes
/
time2CSharp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import sys
import os
from io import StringIO
import contextlib
import subprocess
@contextlib.contextmanager
def stdoutIO(stdout=None):
old = sys.stdout
if stdout is None:
stdout = StringIO()
sys.stdout = stdout
yield stdout
sys.stdout = old
def get_stdin():
buf = ""
for line in sys.stdin:
buf = buf + line
return buf
if __name__ == "__main__":
st = get_stdin()
tmpfold = os.environ["TMPDIR"]
tmpfile = "%s/%s" % (tmpfold, "Program.cs")
f = open(tmpfile, 'w')
f.write(st)
f.close()
os.chdir(tmpfold)
p1 = subprocess.Popen(["dotnet", "build"], stdout=subprocess.PIPE)
pLog = p1.stdout.read()
with stdoutIO() as s:
try:
print(subprocess.check_output(["dotnet", "run"]).decode("utf-8"))
except BaseException as e:
print(e)
print(s.getvalue())