如何在Linux上使用php获得c++编译结果

how to get c++ compile results on linux with php

本文关键字:获得 php c++ 编译 结果 Linux      更新时间:2023-10-16

我想获得编译错误与php。我可以接受一些命令的输出,但我不能接受编译命令的输出。例如:

$compileCode = "g++ -o program program.cpp";
$output = `$compileCode`;

是行不通的。但

$output = `ls -l`;
作品

尝试将stderr重定向到stdout:

$compileCode = "g++ -o program program.cpp 2>&1";
$output = `$compileCode`;

如果您只想看到错误,您也可以将stdout重定向到/dev/null:

$compileCode = "g++ -o program program.cpp 2>&1 1>/dev/null";
$output = `$compileCode`;