Say I wanna test my c++ code but I don't want to do it by hand. I realize I can write a python script that can test my code for me. So I want to test this c++ code for example:
#include <iostream>
#include <string>
using namespace std;
int main() {
string line;
cin >> line;
cout << line << endl;
}
Here is the python script that I tried to test this c++ code:
import subprocess as sb
sb.call("g++ main.cpp", shell=True)
sb.call("./a.out", shell=True)
sb.call("chocolate", shell=True)
This create the a.out
executable file but it doesn't allow me to run my program. How can I make this work? Or is there something better that I can do?