Issue
I have a python script that I want to execute in my Laravel application through the pressure of a button and then save in a DB some data that returns me the script. I use symfony/process but I don't get the desired result. Someone can help me?
My view in Laravel is this:
<form action="{{ url('admin/scan') }}" method="POST">
@csrf
<button type="submit" class="btn btn-ghost-primary" id="scan">Scan Device</button><br>
</form>
The controller is this:
public function scan()
{
$process = new Process(['python', 'C:\Simone\Università\Smart IoT Devices\Lab_Raspy\Bluetooth\prova.py']);
$process->run();
$process->getOutput();
}
And the Route is:
Route::post('scan', [DataFromRaspController::class, 'scan'])->name('scan');
Solution
To troubleshoot your problem, please check the exception. By default, it doesn't show any underlying errors.
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
Don't forget to include,
use Symfony\Component\Process\Exception\ProcessFailedException;
Answered By - Abdullah Al Farooq
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.