Как перехватить синтаксические ошибки в Java, если я компилирую код с помощью метода PHP exec ()?

Код в PHP с использованием команды exec () выглядит следующим образом:

exec('javac -classpath dir test.java');

Мне интересно, как я могу поймать синтаксические ошибки, которые существуют в файле test.java.

0

Решение

Вам нужно перенаправить stderr в stdout,

присоединять 2>&1 до конца вашей команды

exec('javac -classpath dir test.java 2>&1',$op);
var_dump($op);

Вот 2 это stderr и 1 это стандартный вывод

1

Другие решения

Если вы используете все 3 exec аргументы, вы увидите вывод:

от http://php.net/manual/en/function.exec.php

string exec ( string $command [, array &$output [, int &$return_var ]] )

exec() executes the given command.
Parameters ¶

command

The command that will be executed.
output

If the output argument is present, then the specified array will be filled with every line of output from the command. Trailing whitespace, such as \n, is not included in this array. Note that if the array already contains some elements, exec() will append to the end of the array. If you do not want the function to append elements, call unset() on the array before passing it to exec().
return_var

If the return_var argument is present along with the output argument, then the return status of the executed command will be written to this variable.
1

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector