shell.run variant which accepts quoted arguments
SquidDev opened this issue ยท 0 comments
The "correct" way to start another program is to use shell.run
. However, in some (admittedly rare) cases, its behaviour is non ideal.
The problem is that shell.run
concatenates all its arguments together before parsing them as a command line. This means that shell.run("cd foo")
is identical to shell.run("cd", "foo")
. However, this is also true when later arguments have spaces in them. For instance, shell.run("cd", "foo bar")
is equivalent to shell.run("cd foo bar")
.
This is problematic when you look at the monitor
or shell
programs - monitor right edit "my code.lua"
actually ends up executing edit my code.lua
!
While this can be avoided by escaping the inputs (using ("%q"):format(x)), I think the cleanest thing here is to expose the internal
runfunction as
shell.execute` (probably with some additional argument validation). The monitor and shell programs call then that instead (though with some fallback for custom shells which don't support it yet).