0

I am designing a web application which uploads code from server and runs cppcheck on it. I am using PHP for the same. I tried using exec($command,$output,$status); command and command is "cppcheck ". $filename;

The $output array which is returned contains only the first line i.e.:

Checking file.cpp..

The line

"(error) Array 'a[10]' accessed at index 10, which is out of bounds."

is displayed in the error.log file of the httpserver. It is actually not a command line error or php error, but an error produced by cppcheck. Is it because the string contains "error" it goes into error.log? How do I fix this?

1
  • Most likely that cppcheck command outputs the error message on the stderr stream. You have to redirect it to stdout then. Something like this: exec('cppcheck somefile 2>&1',$output,$status);. Commented Mar 21, 2015 at 9:36

1 Answer 1

0

As @arkascha pointed out correctly, the output from cppcheck has to be redirected from the stderr stream to stdout.

According to the manual, chapter 2.7:

Many times you will want to save the results in a file. You can use the normal shell redirection for piping error output to a file.

cppcheck file1.c 2> err.txt

Your call would then be

exec($command.' 2>&1', $output, $status);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.