lua-users home
lua-l archive

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

On windows I have to quote both argument and the whole command

"lua "folder one/file.lua""
On 7 Feb 2021, 15:00 +0300, v <>, wrote:
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

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.


v <>