I am trying to make python program to score the homework written in c++. My laptop os is window so i installed g++ in order to use subprocess command. This is my code.
Python code:
import subprocess
import os
import glob
from openpyxl import Workbook
path='C:\\auto_scoring\\'
def write_csv(tc_num,ans):
score_book=Workbook()
def score(testcases):#scroing function
correct=True
for i,testcase in enumerate(testcases):
if correct:
print(i+1,":correct")
else :
print(i+1,":wrong")
def exe_maker(filename):
ret=filename.rstrip('.cpp')+'.exe'
return ret
def execute(file):
ret=subprocess.check_output('check')
def get_testcase():
global path
text_name='test.txt'
r=open(text_name,mode='r',encoding='utf8')
text=r.read()
print(text)
def run():
file_list = glob.glob('*.cpp*')#cpp
for file in file_list:
exe_file=exe_maker(file)
command='g++ -o '+path+exe_file+" "+path+file
print(command)
subprocess.call(command)
print("start!")
ret=subprocess.check_output(file.rstrip('.cpp')+" 1").decode('ascii')
print(ret)
def main():
run()
def exp():
ret=subprocess.check_output('check').decode('ascii')
if ret=='1':
print('correct')
else:
print('wrong')
if __name__=='__main__':
main()
But I have to use pass the parameter such as C++ example:
int main(int argc,char*argv){
cout<<argv[1];
}
I don't want to use this kind of thing. Program without int argc and char argv. I just want to check whether the answer is correct. For example) input: My name is k -> output: Hello K. If i couldn't make the program , I have to run every 100 c++ files... I really need help. thank you.