Skip to content

Running commands in strings fails #623

Closed
@miversen33

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions