I'm trying to write a Python program to mark/score a C program.
The C program to be tested is supposed to output something like
0102210303 Michael
Here is the code uploaded by a unqualified student.
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv)
{
if (argc == 1)
printf("0102210303 Michael\n");
printf("%d", strcmp(argv[1], "0102210303"));
return 0;
}
which outputs
0102210303 Michael
Segmentation fault (core dumped)
I tried the following Python code to catch the output and error
result = subprocess.run(['./a.out'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print(result.stdout.decode("utf-8"))
print(result.stderr.decode("utf-8"))
neither stdout nor stderr catches the output, how do I capture something like
0102210303 Michael
Segmentation fault (core dumped)
with Python?