Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run python code from ace editor

I am working on a project that uses ace editor.

I want to take the user's inputted python code and run the code and show the user the output. I know that this can be done for javascript but can it be done for python.

Any help would be apreciated.

like image 713
Subhan Mahmood Avatar asked Nov 09 '22 15:11

Subhan Mahmood


1 Answers

To do that you have to get server side script support(PHP,ASP,JSP.. )

I can give you example from PHP, You have to send ace editor input to server and get executed output back to the output window, this question is broad, I gave you server side part !

<?php
   $myfile = fopen("main.py", "w") or die("Unable to open file!");
    $txt = "#print (\"Hello World!\")";
    fwrite($myfile, $txt);
    fclose($myfile);
    $output = `python main.py`;
    echo "<pre>$output</pre>";
?>

Further reading DOC
N.B :pyhton should be installed on your server and you should have permissions

The backtick operator is disabled when safe mode is enabled or shell_exec() is disabled.

hope this will be helpful !

like image 169
Alupotha Avatar answered Nov 15 '22 06:11

Alupotha