2012-12-28 152 views
3

這個問題不是讀取lua文件,而是讀取lua中只讀非可執行文件。Lua讀取只讀文件

我有以下文件

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 

但是當我嘗試用下面的代碼讀取它在Lua我得到許可被拒絕的錯誤。請有人解釋我爲什麼?如何在不更改權限的情況下讀取文件?

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

該錯誤消息(與在LUA殼鍵入的代碼放在一起:

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 

回答

5

使用io.open而不是io.popen如果你打算讀它爲文本文件