在php中捕获c程序的错误

时间:2018-02-18 10:59:13

标签: php html



<html>
<?php
$current="";
$answer="";

if(!empty($_POST))
{
	$current=$_POST['t1'];
	$file="hello.cpp";
	file_put_contents($file,$current);
	putenv("PATH=C:\Program Files (x86)\Dev-Cpp\MinGW64\bin");
	$error=shell_exec("g++  -Wall -o hello hello.cpp");
	$answer=shell_exec("hello.exe");
}
?>
<style>
.txtarea{
width:300px;
height:500px;}
</style>
<form method="POST">
<textarea name="t1" placeholder="Enter c++ code" class="txtarea"><?php echo $current; ?></textarea>
<input type="submit" value="run">
<textarea name="t2" class="txtarea"><?php echo $answer; ?></textarea>
<br>
<textarea name="t3" class="t"><?php echo $error; ?></textarea>
</form>
</html>
&#13;
&#13;
&#13;

我尝试运行在文本区域中编写的c程序并将其输出到另一个文本区域。为了测试我只写了一个简单的hello world程序,它运行正常。但问题是,如果我删除&#34 ;;&#34;从printf语句中,错误消息未存储在$ error变量和文件&#34; hello.exe&#34;也没有创建。 有没有办法捕获编译错误? 这里我使用的是dev c ++编译器。

0 个答案:

没有答案