通过PHP构建g ++:无构建输出 [英] Building g++ via PHP: no build output
本文介绍了通过PHP构建g ++:无构建输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在服务器上构建一个cgi文件.编译一个简单的测试c ++文件是可以的.问题是,无论成功还是失败,我都无法获得任何构建输出.
I need to build a cgi file on a server. Compiling a simple test c++ file is working ok. The problem is I can not get get any build output, neither on success or failure.
<?php
header("Content-Type: text/plain");
$input = "test.c";
$output = "test.cgi";
//$cmd = "g++ --version";
$cmd = "g++ -g -Wall -O $input -o $output";
$retval = 0;
$errors = [];
exec($cmd, $errors, $retval);
foreach ($errors as $key => $line)
{
echo "$key $line" . PHP_EOL;
}
echo (intval($retval) ? "ERROR" : "OK") . PHP_EOL;
?>
当我运行"g ++ --version"时,我确实得到了输出,但是在编译时却没有.
when I run "g++ --version" I do get output, but not when compiling.
G ++版本从2015年开始
The G++ version is from 2015
推荐答案
尝试使用 2>& 1
将错误输出重定向到标准输出:
Try redirecting the error output to the standard output with 2>&1
:
$cmd = "g++ -g -Wall -O $input -o $output 2>&1";
您还可以通过执行以下操作从 exec()
或 shell_exec()
以字符串形式获取输出:
You can also get the output as a string from exec()
or shell_exec()
by doing:
$output_message = exec($cmd, $errors, $retval);
这篇关于通过PHP构建g ++:无构建输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文