lua中执行shell

511 词
文章目录
</div>


<h3 id="直接执行Shell"><a href="#直接执行Shell" class="headerlink" title="直接执行Shell"></a>直接执行Shell</h3><p>直接执行xxx指令</p>
os.execute('xxx')

以指定用户执行Shell

pi用户执行ls

os.execute('su -s /bin/bash -c "ls" pi')

屏幕亮

os.execute('su -s /bin/bash -c "xset dpms force on" pi')

屏幕灭

os.execute('su -s /bin/bash -c "xset dpms force off" pi')

获取执行结果

获取ls执行结果

local t = io.popen('ls')
local s = t:read("*all")
t:close()