-
Notifications
You must be signed in to change notification settings - Fork 18
/
python27.php
47 lines (43 loc) · 957 Bytes
/
python27.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
$CC="python2.7";
//$out="./a.out";
$code=$_POST["code"];
$input=$_POST["input"];
$filename_code="main.py";
$filename_in="input.txt";
$filename_error="error.txt";
//$executable="a.out";
$command=$CC." ".$filename_code;
$command_error=$command." 2>".$filename_error;
//if(trim($code)=="")
//die("The code area is empty");
$file_code=fopen($filename_code,"w+");
fwrite($file_code,$code);
fclose($file_code);
$file_in=fopen($filename_in,"w+");
fwrite($file_in,$input);
fclose($file_in);
//exec("chmod 777 $executable");
exec("chmod 777 $filename_error");
shell_exec($command_error);
$error=file_get_contents($filename_error);
if(trim($error)=="")
{
if(trim($input)=="")
{
$output=shell_exec($command);
}
else
{
$command=$command." < ".$filename_in;
$output=shell_exec($command);
}
echo "<pre>$output</pre>";
}
else
{
echo "<pre>$error</pre>";
}
exec("rm $filename_code");
exec("rm *.txt");
?>