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?

x29a
  • 1,761
  • 1
  • 24
  • 43
Ruchi Tengse
  • 87
  • 1
  • 7
  • 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);`. – arkascha Mar 21 '15 at 09:36

1 Answers1

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);
x29a
  • 1,761
  • 1
  • 24
  • 43