PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, February 4, 2022

[FIXED] Execute python file in Laravel and save data into DB

 February 04, 2022     database, laravel, python     No comments   

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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing