Reputation: 336
I have been trying to implement an ide on my website. Like if I want to run this program:
/* add c headers if necessary*/
#include <stdio.h>
/* Include other headers as needed */
int main()
{
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int a,b;
scanf("%d%d",&a,&b); // requires user input
return 0;
}
This program will get executed at my Linux server using some script.
As this program requires input from user,I have provided a textbox to user to provide that input. Then, I save that input in some file at my backend and supplying it through that file to my program and corresponding result is shown on my webpage.
But now I want user give input one by one.
For this I will need to catch when it requires input through my script then I will terminate my script and send response to user for that input.... Then will be feeding that input to program and again do the same if again some input require.
If something not clear please ask...
Upvotes: 2
Views: 1117
Reputation: 27195
There is very similar question without a satisfying answer.
Maybe you could approach the problem from a different angle. Instead of
you could send outputs and inputs immediately. In a terminal, the user can always type. Simulate that behavior on your website.
Sending things immediately should be doable. There are websites that do send inputs and outputs immediately, for instance etherpads like this one (try it with a normal and a private browser window opened at the same time and site).
On your server, you can store the user's input and program's output in two temporary files. For one session, you could run something like the following script
# skeleton of the server script
compile program.c
createEmptyFiles input output
tail -f input | ./program > output
Additionally you need to feed the user's input into input
and send the program's output to the user.
Upvotes: 1