-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmpcplus.py
47 lines (44 loc) · 1.3 KB
/
cmpcplus.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
# -*- coding: UTF-8 -*-
import os
import subprocess
import sys
import time
class cplus:
def __init__(self):
self.filename=""
def compiletest(self):
s=-1
s=os.system("g++ "+sys.path[0]+"\\"+self.filename+" -o "+sys.path[0]+"\\demo.exe")
while(s==-1):
time.sleep(0.1);
if(os.path.exists(sys.path[0]+"\\demo.exe")):
return True#没有error返回true
else:
return False
def run(self):
a=-1
a=os.system(sys.path[0]+"\\demo.exe")
while(a==-1):
time.sleep(0.1)
def fileerrortest(self,files):
if(os.path.exists(sys.path[0]+"\\"+files+".out")):#判断文件是否存在
return True#没有error返回true
else:
return False
def runtimetest(self,files):
if(os.path.exists(sys.path[0]+"\\"+files+".out")):
fd=open(files+".out",'r')
if(fd.read()==""):
fd.close()
return False#有error返回false
else:
fd.close()
return True
if(__name__=='__main__'):
print(sys.path[0])
test=cplus()
test.filename="hello.cpp"
print(test.compiletest())
test.run()
print(test.fileerrortest("hello"))
print(test.runtimetest("hello"))