Я пытаюсь сделать python программу для оценки домашнего задания, написанного на с ++. Мой ноутбук OS является окном, поэтому я установил g ++ для использования команды подпроцесса. Это мой код.
Python код:
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()
Но я должен передать параметр, такой как пример C ++:
int main(int argc,char*argv){
cout<<argv[1];
}
Я не знаю Я не хочу использовать такие вещи. Программа без int arg c и char argv. Я просто хочу проверить, правильный ли ответ. Например: input: меня зовут k -> output: Hello K. Если я не смог создать программу, мне нужно запускать каждые 100 файлов c ++ ... Мне действительно нужна помощь. спасибо.