从laravel执行python脚本



按下按钮后,我应该从Laravel中的视图中执行python中的脚本。在控制器中,我放入代码来执行脚本,即:

public function scan()
{
$process = new Process(['C:SimoneUniversitySmart IoT DevicesLab_RaspyBluetooth', 'prova.py']);
$process->run();
if (!$process->isSuccessful()) { throw new ProcessFailedException($process); }
return redirect()->route('device');
}

但是当我按下视图中的按钮时,我会得到这个错误:

命令"'C: \西蒙\大学\智能物联网设备\Lab_Raspy\Bluetooth"prova.py";失败。退出代码:127(命令找不到(工作目录:/var/www/html/public输出:====================错误输出:====================sh:1:exec:C:\Simone\University\Smart IoT Devices\Lab_Raspy\Bluetooth:未找到

视图设置如下:

@extends('backend.layouts.app')
@section('content')
<form action="{{ url('admin/scan') }}" method="POST">
@csrf
<button type="submit" class="btn btn-ghost-primary" id="scanner">Scan Device</button><br><br>
</form>
<table class="table">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">USERNAME</th>
<th scope="col">MAC ADDRESS</th>
</tr>
</thead>
<tbody>
@foreach ($data as $item)
<tr>
<th scope="row">{{$item->id}}</th>
<td>{{$item->USERNAME}}</td>
<td>{{$item->MAC_ADDR}}</td>
<td>
<a href="/admin/singleDevice/{{ $item->id }}" class="btn btn-primary">Select</a>
</td>
</tr>
@endforeach
</tbody>
</table>
@endsection

UPDATE我也尝试了命令

$process = shell_exec('python C:SimoneUniversitàSmart IoT DevicesLab_RaspyBluetoothprova.py 2>&1');

return redirect()->route('backend.auth.user.device');

和错误的变化:

Symfony\Component\Routing\Exception\RouteNotFoundException路由未定义[backend.auth.user.device]。

我的路线是:

Route::get('device' ,[DeviceController::class, 'index'])->name('devices');
Route::get('dict', [DeviceController::class, 'visualizeData'])->name('dict');
Route::get('singleDevice/{device}', [DeviceController::class, 'singleDev'])->name('singleDev');
Route::get('scan', [DeviceController::class, 'scan'])->name('scan');

我哪里错了?

您是否只尝试了一个简单的

$command='python C:\Simone\Università\智能物联网设备\Lab_Raspy\Bluetooth \prova.py 2>amp;1';

exec($command,$output(;

最新更新