我想制作一个在线编译器。
我正在计算机上测试我的所有代码(我安装了php)。
我编写了这段代码进行编译,但它没有工作(我正在寻找太多时间,但我没有找到
<?php
$file="prog.cpp";
function kompiluj(){
global $file;
$polecenie = 'g++ '.$file.' -o a.exe ';
global $errorFlag;
global $errorDetail;
$output = exec($polecenie, $errorDetail, $errorFlag);
echo $errorDetail;
echo $errorFlag;
echo $output;
}
?>
也许有人知道修这个?非常感谢你:P
- 编辑:
例如我的prog.cpp看起来像
include <iostream>
using namespace std;
int main() {
cout<<"TEST";
return 0;
}
我的功能应该写&#34; TEST&#34;,但它只写了:
阵 1
我该怎么做?
答案 0 :(得分:0)
从PHP文档中不清楚exec
是否调用了shell,但即使这样,它也可能提供最小的环境。无论哪种方式,您可能需要提供g++
的完整路径。尝试更改此内容:
$polecenie = 'g++ '.$file.' -o a.exe ';
......对此:
$polecenie = '/usr/bin/g++ '.$file.' -o a.exe ';
...并确保验证g++
的完整路径。