inputfile.write("47");
cmd = ["gcc", "-O2", srcname, "-o", execname];
p = subprocess.Popen(cmd,stderr=errfile);
errfile.close();
#print(p)
p.wait();
...
subprocess.call(["./"+execname],stdin=inputfile,stdout=outputfile)
Above is some portion of my code to compile a C program using Python.
srcname is the input .c filename
execname is the C Executable filename
subprocess.Popen(cmd,stderr=errfile); // This is compiling my C program and printing the errors in errfile
subprocess.call(["./"+execname],stdin=inputfile,stdout=outputfile)// This is executing my C file on the condition that compilation is succesful
Below is my C source code in the file named srcname:
#include <stdio.h>
int main(int argc, char *argv[])
{
int n;
scanf("%d",&n);
printf("%d",n);
}
My inputfile contains 47 (refer first line). But the outputfile always contains 14.
using the below command line argument, I am getting right output in the output file.
C:/gcc srcname.c
C:/a.exe<input.txt>output.txt