lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 30 August 2013 03:04, Ousmane Roland Yonaba <roland.yonaba@gmail.com> wrote:
> Hi community,
>
> It is known that one can execute shell commands via Lua's native os.execute,
> or io.open.
> I am willing to get the output of a specific command. This command is
> supposed to return an output, but can also fairly err, depending on the user
> configuration.
>
> The thing is, when we actually input a wrong command in a shell output, it
> prints an an error message readily, while still running the Lua program.
> Well, is it possible to somehow shadow that error message ? Catching the
> output, redirecting it somewhere else, and then display (or not) a
> custom-made report instead ? If so, can I have some pointers, in terms of
> code ?
>
> As I am horrible at stating things in simple and few words (I do admire
> native english-speaking people conciseness), I can come up with an example,
> if needed.
>
>
> Best regards,
> Roland Y.

If the command always outputs its errors in a specific format, you
could run the command with io.popen, read the output from the returned
file handle and then parse it (with the string library, LPEG or your
regex library of choice). If the output matches the format of an
error, report it as needed; otherwise do whatever you need with the
command's output.

I can't really provide any examples without knowing the command and
its output formats.