2

I was working on a project similar to that on Code Pad . I have a php form that calls the c compiler on the linux server. The compiler compiles and executes and sends the output to a file that a php script reads and displays.

I have challenges with rendering Input operations that way.

I tried scanning the source code file for any input function then ask the user to enter values for each corresponding variable in the input function, then i stored the users value in a text file which i then pass to the c program as stdin.

It worked for basic programs - but in cases where there are conditional statements, that wouldn't work.

I was thinking if it would be possible to have a terminal on the webpage that users can access and execute thier programs on.

Or would there be any other way i can effectively handle this?

1 Answer 1

2

Use proc_open to start a subprocess with detailed control. Redirect stdin, stdout, and stderr of the started process to files (or pipes, if you impose strict limits on runtime and number of concurrent processes).

Then, use websockets or an alternative to communicate between browser and php, and relay input/output between web client and executed program.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your answer - but i have never worked with proc_open() or websocketes. do u have any example that i can view? maybe a link or something
@OkwuokenyeEbuka The linked documentation contains an example of proc_open. Websockets (or any alternative) requires careful engineering. Here's an example of phpwebsocket usage.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.