I have a custom codechecker in python, Also there is a bigger project running in PHP, which stores users code in MySQL database.
I am new to python, so I'm not sure how I can pass the code from PHP to Python.
Do I have to store the file to the filesystem to pass it to Python? (In that case too many files might be created, and their cleanup after execution has to be taken care)
-
What form does the code needing to be checked take? Can you provide an example?Eli Stevens– Eli Stevens2012年03月09日 04:25:05 +00:00Commented Mar 9, 2012 at 4:25
-
code is any general C/C++, Java, Python code, which will take input from STDIN and output to STDOUT, as a example: #include<cstdio> int main() { int a; scanf("%d",&a); printf("%d\n",2*a); }Chakradar Raju– Chakradar Raju2012年03月09日 04:26:48 +00:00Commented Mar 9, 2012 at 4:26
2 Answers 2
To expand on Brad's answer, there's several options, each with pros & cons...
- Pipes (ie: STDIN/STDOUT):
proc_open() - Shared memory:
shmop_open() - AF_UNIX family sockets:
socket_bind()
You'll probably want to use the first option but read up on the others before making a commitment.
Comments
Just use STDIN/OUT.
See proc_open() to get at the pipes you need.