Reputation: 4278
hi friends i am a degree student and thinking of a online c compiler as my final year project just like the codepad & ideone.
So this is the idea :
I'll have a server with compiler that will accept code from client, compile it and then execute it. The result of will be sent back to client.
The client can use my android application or desktop browser to type and send code to server.
Ofcourse there will be security issues that can be handled by sandboxing and chrootjail and other techniques.
My question is that i want to connect input stream of running program to users input (either browser or android application interface). So that he can type in the input while the program is executing.
Example :
void main()
{
int i;
printf("\n\n\t Enter i's value : ");
scanf("%d",&i);
// Here the program should wait till the user type input in browser or app. and then it should proceed.
}
My question is how can i achieve this.? I will have to make program execute on server and connect it's input stream to client by coding.
The user can type in the input just like he can type in on a program executing on his local machine.
So any ideas?
Upvotes: 0
Views: 1186
Reputation: 182827
For every user program that you are running, also have a manager program that launches it and handles its communication with the user. Have the manager program create two pipes, one will be the program's input, the other will be the program's output. (Or three if you want to handle error output separately.)
When you get information from the user that needs to go to the user's running program, hand it to the manager process by any mechanism you like. The manager process can then send it on the pipe hooked up to the user process' standard input. When the manager sees data on the pipe hooked to the user process' standard output, have it put it someplace your code that communicates with the user can get it to send to the user.
Upvotes: 1