-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile.py
105 lines (76 loc) · 2.37 KB
/
compile.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env python3
import sys
import os
import subprocess
code = sys.argv[1]
lang = code.split('.')[1]
if lang == 'cpp':
command = 'g++'
argv1 = '-o'
argv2 = 'tes1'
argv3 = code
argv4 = '<'
argv5 = 'input.txt'
output = subprocess.Popen([command, argv1, argv2, argv3], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
res = output.communicate();
if res[1].decode('utf-8') is not '':
print(res[1].decode('utf-8'))
command = 'rm'
subprocess.Popen([command, argv3, argv5])
sys.exit(1)
command2 = './tes1 < input.txt'
output1 = subprocess.call(command2, shell=True)
command = 'rm'
argv = 'tes1'
subprocess.Popen([command, argv, argv3, argv5])
print(output1)
elif lang == 'py':
command = 'python3'
argv = code
argv4 = '<'
argv5 = 'input.txt'
output = subprocess.Popen([command, argv, argv4, argv5], stdout=subprocess.PIPE, stderr=subprocess.PIPE);
res = output.communicate()
if res[1].decode('utf-8') is not '':
print(res[1].decode('utf-8'))
else:
print(res[0].decode('utf-8'))
command = 'rm'
subprocess.Popen([command, argv, argv5]);
elif lang == 'c':
command = 'gcc'
argv1 = '-o'
argv2 = 'tes1'
argv3 = code
argv4 = '<'
argv5 = 'input.txt'
output = subprocess.Popen([command, argv1, argv2, argv3], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
#print("YO: ",output.communicate())
res = output.communicate();
if res[1].decode('utf-8') is not '':
print(res[1].decode('utf-8'))
command = 'rm'
subprocess.Popen([command, argv3, argv5])
sys.exit(1)
command2 = './tes1 < input.txt'
output1 = subprocess.call(command2, shell=True)
command = 'rm'
argv = 'tes1'
subprocess.Popen([command, argv, argv3, argv5])
print(output1)
else:
command = 'ruby'
argv = code
argv4 = '<'
argv5 = 'input.txt'
output = subprocess.Popen([command, argv, argv4, argv5], stdout=subprocess.PIPE, stderr=subprocess.PIPE);
res = output.communicate();
if res[1].decode('utf-8') is not '':
print(res[1].decode('utf-8'))
command = 'rm'
argv2 = code
subprocess.Popen([command, argv, argv5])
sys.exit(1)
print(res[0].decode('utf-8'))
command = 'rm'
subprocess.Popen([command, argv, argv5])