
由于在做c++信奥教学,出于某种考虑,可能会用到本地的OJ练习系统。略作修改也可以成为测试系统。用Python开发是比较简单的,不像网络的OJ平台,本地OJ不用考虑太复杂的用户情况,只需处理好最基本的几个问题即可,下面简单介绍一下。
一、源代码编译
源代码编译,是通过直接调用MinGW64实现的。
def makeExe(cpp):
command= r'MinGW64\bin\g++.exe %s -o %s -m32'
# command= r'gcc\bin\g++.exe %s -o %s -m32'
exe= filetool.changeExt(cpp, '.exe')
command= p1+ "\\"+ command%(cpp, exe)
# print(command)
cmd= command.split()
# print(cmd)
sp = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = sp.communicate()
ret= ""
if out:
ret+= out.decode("utf-8")
if err:
ret+= err.decode("gbk")
ret= ret.strip()
return ret
二、运行EXE,给与输入并得到结果
# 测试exe文件的执行,并用对


1207

被折叠的 条评论
为什么被折叠?



