lua-users home
lua-l archive

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


For your case it would be

io.popen('otfinfo -p "/path/to/file name/ with spaces.otf"', 'r')

Escape it like you would in usual shell, that's the general rule.

The deeper problem here is that you can't reliably escape user input
(well, you theoretically can, but good luck with that), and all ways
Lua allows to call a command require you to escape inputs (due to
portability requirements, it's the only way ANSI C provides). You also
can only have one I/O stream (stdin/stdout/stderr) open per child
process, but not more. You probably want to take a look at lua-
subprocess or luaposix libraries that allow to bypass both of those
limitations.

On Sun, 2021-02-07 at 00:30 -0800, Robin Stern wrote:
> Hi there,
> Am new to lua, and coming here from Python land. One thing that I
> have been not able to get right after browsing internet for 2 hours
> (and trying solutions) is run a simple command from within lua, and
> get the stdout, stderr for it. Here's the command:
> 
> otfinfo -p /path/to/file name/ with spaces.otf
> 
> It will be great if someone can give a complete solution. The path to
> filename is coming from a list that does not escape spaces, so spaces
> are just ' ' characters.
> 
> Thanks!

-- 
v <v19930312@gmail.com>