Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lua read read-only files

Tags:

lua

This question is not about reading lua files, but reading read only non-executable files in lua.

I have a following file

10 awesome % ls -l /sys/class/backlight/intel_backlight/actual_brightness                                                                                      
-r--r--r-- 1 root root 4096 Dec 28 20:17 /sys/class/backlight/intel_backlight/actual_brightness

But when I try to read it in lua with the following code I get an error that the permission is denied. Could someone, please, explain me why? How can I read the file without changing its permissions?

file = io.popen('/sys/class/backlight/intel_backlight/actual_brightness', 'r')
output = file:read('*all')
file:close()

The error message is (together with the code typed in in the lua shell:

12 awesome % lua                                                                                                        
Lua 5.2.1  Copyright (C) 1994-2012 Lua.org, PUC-Rio
> file = assert(io.popen('/sys/class/backlight/intel_backlight/actual_brightness', 'r'))
> sh: /sys/class/backlight/intel_backlight/actual_brightness: Permission denied
^C
like image 370
aignas Avatar asked Sep 02 '26 00:09

aignas


1 Answers

Use io.open instead of io.popen if you intend to read it as text file.

like image 195
neo Avatar answered Sep 04 '26 23:09

neo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!