I've a code for command app made on laravel 5.0 with try .. catch and use system command. When there a exception, my catch not work.
use Illuminate\Support\Facades\Log;
...
try {
system('.dump master | sqlite3 ' . $older . ' > ' . storage_path() . '/tmp/' . $tabla . '.sql' );
} catch ( \Exception $e) {
Log::alert('Problem import old table '. $tabla . $e->GetMessage());
}
I see my error on shell but not write on my own laravel log. (Log:alert)
Use Throw Exception in php. Here is the reference link to use and a sample example:
You have to gain access over
STDERR
and, probably,STDOUT
. Use proc_open, e.g.:Of course, there is no need in
STDOUT
pipe, if the command redirects it to a file.And yes,
system()
won't throw exceptions. Obviously, you can implement your own class which will throw an exception in case if the process exit status is non-zero, or there is something caught in theSTDERR
pipe: