Compruebe si un archivo Java se compiló correctamente usando PHP

So I need to check out the output of a Java program I am compiling and running using PHP:

$output = shell_exec('cd write && javac JavaCode.java && java JavaCode');

I don't get anything written to the $output string if the javac command fails. So how do I perform these operations and checks using PHP?

preguntado el 27 de noviembre de 13 a las 01:11

3 Respuestas

Deberías estar recibiendo NULL returned if there was an error.

De los documentos:

The output from the executed command or NULL if an error occurred or the command produces no output.

Intente var_dump($output) and see what it returns

respondido 27 nov., 13:01

anexar && echo 'message' at the end. Since it's an and, you won't get the message back if any of the commands fail

so

$output = shell_exec('cd write && javac JavaCode.java && java JavaCode && echo \'success\'');

respondido 27 nov., 13:01

exec can give you return value:

  exec('cd write && javac JavaCode.java', $output, $returnValue);
  if ($returnValue == 0) {
      echo 'success';
  } else {
      echo 'compilation failed';
  }

respondido 27 nov., 13:02

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.