Reputation: 197
I want to get compile errors with php. I can take the outputs of some commands but I can't take compile command outputs. for example :
$compileCode = "g++ -o program program.cpp";
$output = `$compileCode`;
doesn't work. But
$output = `ls -l`;
works
Upvotes: 1
Views: 166
Reputation: 11467
Try redirecting stderr to stdout:
$compileCode = "g++ -o program program.cpp 2>&1";
$output = `$compileCode`;
If you want to see only errors, you can also redirect stdout to /dev/null
:
$compileCode = "g++ -o program program.cpp 2>&1 1>/dev/null";
$output = `$compileCode`;
Upvotes: 1