[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Shadow shell error messages when running os.execute/io.popen from Lua
- From: Choonster TheMage <choonster.2010@...>
- Date: Fri, 30 Aug 2013 03:46:22 +1000
On 30 August 2013 03:04, Ousmane Roland Yonaba <email@example.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
> 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
I can't really provide any examples without knowing the command and
its output formats.