实时读取服务器的终端输出(Real-time reading of terminal output from server)
我试图在我的服务器上处理来自相机的图像,并在本地计算机上实时处理后获取信息。 我可以在我的服务器上获取必要的信息作为终端输出,但是我不能把这些信息放到本地机器上的python代码中,直到我的服务器程序运行。 我试过这段代码:
cmd="sshpass -p 'pass' ssh -Y user@ip -t 'process_image; bash -l'" p = subprocess.Popen(cmd, stdout=subprocess.PIPE, bufsize=1) for line in iter(p.stdout.readline, b''): print(line) p.stdout.close() p.wait()
但它不起作用 - 看起来这个代码只是暂停了我的程序。 我试图将输出写入文件并从本地机器读取文件,但它会扭曲我的数据。 我能做些什么来实时读取服务器的终端输出?
I'm trying to process images from my camera on my server and get the information after processing on my local machine in real-time. I can get necessary information as terminal outputs on my server, but I can't put this info in my python code on local machine, until my server program is running. I'm tried this code:
cmd="sshpass -p 'pass' ssh -Y user@ip -t 'process_image; bash -l'" p = subprocess.Popen(cmd, stdout=subprocess.PIPE, bufsize=1) for line in iter(p.stdout.readline, b''): print(line) p.stdout.close() p.wait()
But it doesn't work - it looks like this code just paused my program. I tried to write output to file and than read file from local machine, but it distorts my data. What can i do to read terminal output from server in real-time?
原文:https://stackoverflow.com/questions/41908888
最满意答案
将您的用户模型扩展为创建仅限管理员的版本,而不使用质量分配保护。
在新类中,覆盖
$fillable
属性:class UnprotectedUser extends User { protected $fillable = [<all fields>]; }
然后在管理员专用代码中使用新模型:
$user = UnprotectedUser::create($arrayOfAllFields);
请务必在尽可能多的地方使用原始类别,以便继续利用质量分配保护。
Extend your User model to create an admin-only version without the mass-assignment protection.
In the new class, override the
$fillable
property:class UnprotectedUser extends User { protected $fillable = [<all fields>]; }
Then use the new model in your admin-specific code:
$user = UnprotectedUser::create($arrayOfAllFields);
Be sure to use the original class in as many places as possible so that you can continue to take advantage of the mass-assignment protection.
相关问答
更多-
质量分配是当您将数组发送到模型创建时,基本上在一个单一的过程中设置了一堆模型,而不是一个接一个地, $user = new User(Input::all()); (这不是明确地在模型上单独设置每个值。) 您可以使用fillable来保护您希望实际允许进行更新的字段。 假设您的用户表中有一个user_type字段,并且可以具有user / admin的值 显然,您不希望用户能够更新此值。 理论上来说,如果你使用上面的代码,有人可以注入一个新的user_type字段,并发送'admin'和其他表单数据,并轻 ...
-
因为它是一个has_many关联,所以它应该是复数形式: = f.fields_for :messages do |m| 此外,在控制器中,您将需要: def new @campaign = Campaign.new @campaign.messages.build end Because it's a has_many association it should be in plural form: = f.fields_for :messages do |m| Also, in the c ...
-
Rails:如何设置或切换管理状态而无需进行批量分配?(Rails: How can I set or toggle admin status without mass assignment?)[2024-02-23]
这是一个很好的教程 ,可以满足你的需求。 Here is a great tutorial which fits your needs. -
Model::unguard(); 在4.2 https://laravel.com/docs/5.1/seeding中添加了4.2。 您只需在创建对象之前调用它,然后可以使用createOrUpdate() , firstOrNew() , create()等填充任何字段。 更正,这里是L4.2 API: https ://laravel.com/api/4.2/Illuminate/Database/Eloquent/Model.html#method_unguard 另见: Model::reguar ...
-
Laravel 4 Eloquent Mass Assignment - 修改输入(Laravel 4 Eloquent Mass Assignment - Modify Input)[2022-07-16]
如果您只需要更改输入,则可以执行以下操作: $input = Input::all(); $input['date'] = strtotime($input['date']); Input::replace($input); If you just need to change the Input, you can do: $input = Input::all(); $input['date'] = strtotime($input['date']); Input::replace($input ... -
批量分配并不意味着fillable所有字段都将自动填充。 您仍然可以控制在表格中保存的内容。 所以如果你这样做: $user = User::find(1); $user->email = 'email@emails.com'; $user->save(); 只有电子邮件将保存在上面的示例中,而名称和密码保持不变 Mass assignment doesn't mean all the field listed in fillable will be auto filled. You still have ...
-
将您的用户模型扩展为创建仅限管理员的版本,而不使用质量分配保护。 在新类中,覆盖$fillable属性: class UnprotectedUser extends User { protected $fillable = [
]; } 然后在管理员专用代码中使用新模型: $user = UnprotectedUser::create($arrayOfAllFields); 请务必在尽可能多的地方使用原始类别,以便继续利用质量分配保护。 Extend your User m ... -
Laravel:批量分配插入新记录或更新现有[重复](Laravel: Mass assignment insert new record or update exisiting [duplicate])[2023-03-17]
您可以使用updateOrCreate()方法实现updateOrCreate功能。 用法: Model::updateOrCreate( ['primary_key' => 8], ['field' => 'value', 'another_field' => 'another value'] ); 在您的情况下,您可以通过以下方式使用fit: $user->user_info()->updateOrCreate(['id'=>$user->id],$request->all()); 代替 ... -
我认为这不是Laravel默认功能的原因,因为它有点与路线应该代表什么相反。 换句话说,这不是 Laravel Way 。 为什么不根据用户的角色重定向用户? // ROUTES.php Route::group(['middleware' => 'auth'], function () { Route::get('dashboard', function() { if($this->user->isAdmin()) return redirect('/das ...
-
我建议您查看https://www.learn2torials.com/a/laravel-authentication-based-on-roles教程来解决此问题。 您必须根据您的用户类型使用不同的中间件来处理其权限 I would suggest to take a look at https://www.learn2torials.com/a/laravel-authentication-based-on-roles tutorial to resolve this issue. You have ...