Erdem
Erdem

Reputation: 197

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

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

Answers (1)

Waleed Khan
Waleed Khan

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

Related Questions