【执行无效的linux命令时,Lua脚本无法检测/捕获错误】教程文章相关的互联网学习教程文章

执行无效的linux命令时,Lua脚本无法检测/捕获错误【代码】

我有以下功能,只要我给它一个有效的命令来执行就可以正常工作.只要我给它一个不存在的命令,脚本就会被错误消息中断.#!/usr/bin/lua function exec_com(com)local ok,res=pcall(function() return io.popen(com) end)if ok thenlocal tmp=res:read('*a')res:close()return ok,tmpelsereturn ok,resend end local st,val=exec_com('uptime') print('Executed "uptime" with status:'..tostring(st)..' and value:'..val) st,val=exec...