feeding values to stdin for online judge feeding values to stdin for online judge php php

feeding values to stdin for online judge


If you have the compiled code and knows the language of it, it is a little simpler.

You can use the exec function to execute the code, and you can use as a command, something like this (for a c program, and tested):

$output = array();exec("./main < sample_input.txt", $output);

And if you now inspect the $output var, it has an entry in the array for each line outputted.

Hope this helps.


Exactly, exec is all what you need in PHP.

However, as long as you need not only running but also evaluating, you shouldbuild some shell script to run, feed, receive output and check if output is correct.Remember to properly sandbox that script because it's security threat.

Exec btw. offers also third parameter that is return value. It is very useful as long as you build your own shell script with its own return codes.

exec ('./script.sh',$output,$exit_code)

Remember that php script must have permisions to files and directories.