Skip to content

Instantly share code, notes, and snippets.

@jimut
Created June 1, 2017 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimut/44a88ee8fba54004fef3bd9f7986c7e6 to your computer and use it in GitHub Desktop.
Save jimut/44a88ee8fba54004fef3bd9f7986c7e6 to your computer and use it in GitHub Desktop.
Docs

After recieving the request the following code compiles it

if ($request->lang === 'C') {
    $outputGcc = shell_exec('gcc '.escapeshellarg(storage_path('app/codes/'.$codefile))
            .' -o '.escapeshellarg(storage_path('app/codes/progs/'.$exefile)).' 2>&1');
} else if ($request->lang === 'C++') {
    $outputGcc = shell_exec('g++ '.escapeshellarg(storage_path('app/codes/'.$codefile))
            .' -o '.escapeshellarg(storage_path('app/codes/progs/'.$exefile)).' 2>&1');
}

We open a process with proc_open() and handle it through the following code

if ($request->lang === 'C' || $request->lang === 'C++') {
    $process = proc_open('./'.$exefile, $descriptorspec, $pipes, storage_path('app/codes/progs'));
} else if ($request->lang === 'Java') {
    $process = proc_open('java '.$exefile, $descriptorspec, $pipes, storage_path('app/codes/progs'));
}

Read the docs at http://php.net/manual/en/function.proc-open.php to understand the rest of the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment