Closed
Description
Hello! I have found an interesting issue when running a command with uv.spawn
Below is an example lua script that will fail, though if you run the command in a linux shell, the command is valid.
-- test.lua
local uv = require("luv")
local handle = nil
local on_exit = function(code, signal)
print(string.format("Exit Code: %s", code))
print(string.format("Exit Signal: %s", signal))
handle:close()
end
local stdout = uv.new_pipe(false)
local stderr = uv.new_pipe(false)
-- This command `/bin/sh -c 'touch /tmp/testing.txt'` is a valid linux command, but this script fails out
local command = "/bin/sh"
local args = {"-c", "'touch /tmp/testing.txt'"}
local opts = {
args = args,
stdio = {nil, stdout, stderr}
}
handle, _ = uv.spawn(command, opts, on_exit)
stdout:read_start(function(err, data)
assert(not err, err)
print(string.format("%s", data))
end)
stderr:read_start(function(err, data)
assert(not err, err)
print(string.format("Error: %s", data))
end)
uv.run()
The above will drop the following output
$ lua test.lua
Error: /bin/sh: line 1: touch /tmp/testing.txt: No such file or directory
Error: nil
nil
Exit Code: 127
Exit Signal: 0
However, this is not the case when you run the command via a shell
$ /bin/sh -c 'touch /tmp/testing.txt'
$ echo $?
0
I assume I am doing something wrong but I dont really know. I have tried breaking the string arg up by space but I get the same error. Any ideas?
Metadata
Metadata
Assignees
Labels
No labels
Activity