{"id":13776253,"url":"https://github.com/openresty/lua-resty-shell","last_synced_at":"2025-05-11T10:30:52.753Z","repository":{"id":45370947,"uuid":"168475284","full_name":"openresty/lua-resty-shell","owner":"openresty","description":"Lua module for nonblocking system shell command executions","archived":false,"fork":false,"pushed_at":"2023-11-23T11:39:34.000Z","size":26,"stargazers_count":120,"open_issues_count":7,"forks_count":18,"subscribers_count":19,"default_branch":"master","last_synced_at":"2024-02-13T20:34:59.456Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/openresty.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-01-31T06:33:36.000Z","updated_at":"2023-11-14T06:59:28.000Z","dependencies_parsed_at":"2023-11-23T12:44:10.683Z","dependency_job_id":null,"html_url":"https://github.com/openresty/lua-resty-shell","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openresty%2Flua-resty-shell","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openresty%2Flua-resty-shell/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openresty%2Flua-resty-shell/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openresty%2Flua-resty-shell/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openresty","download_url":"https://codeload.github.com/openresty/lua-resty-shell/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253551495,"owners_count":21926303,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T18:00:20.685Z","updated_at":"2025-05-11T10:30:52.249Z","avatar_url":"https://github.com/openresty.png","language":"Perl","funding_links":[],"categories":["Libraries"],"sub_categories":[],"readme":"Name\n====\n\nlua-resty-shell - Lua module for nonblocking system shell command executions\n\nTable of Contents\n=================\n\n* [Name](#name)\n* [Synopsis](#synopsis)\n* [Functions](#functions)\n    * [run](#run)\n* [Dependencies](#dependencies)\n* [Author](#author)\n* [Copyright \u0026 Licenses](#copyright--licenses)\n\nSynopsis\n========\n\n```lua\nlocal shell = require \"resty.shell\"\n\nlocal stdin = \"hello\"\nlocal timeout = 1000  -- ms\nlocal max_size = 4096  -- byte\n\nlocal ok, stdout, stderr, reason, status =\n    shell.run([[perl -e 'warn \"he\\n\"; print \u003c\u003e']], stdin, timeout, max_size)\nif not ok then\n    -- ...\nend\n```\n\nFunctions\n=========\n\nrun\n---\n\n**syntax:** `ok, stdout, stderr, reason, status = shell.run(cmd, stdin?, timeout?, max_size?)`\n\n**context:** `all phases supporting yielding`\n\nRuns a shell command, `cmd`, with an optional stdin.\n\nThe `cmd` argument can either be a single string value (e.g. `\"echo 'hello,\nworld'\"`) or an array-like Lua table (e.g. `{\"echo\", \"hello, world\"}`). The\nformer is equivalent to `{\"/bin/sh\", \"-c\", \"echo 'hello, world'\"}`, but simpler\nand slightly faster.\n\nWhen the `stdin` argument is `nil` or `\"\"`, the stdin device will immediately\nbe closed.\n\nThe `timeout` argument specifies the timeout threshold (in ms) for\nstderr/stdout reading timeout, stdin writing timeout, and process waiting\ntimeout. The default is 10 seconds as per https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/pipe.md#set_timeouts\n\nThe `max_size` argument specifies the maximum size allowed for each output\ndata stream of stdout and stderr. When exceeding the limit, the `run()`\nfunction will immediately stop reading any more data from the stream and return\nan error string in the `reason` return value: `\"failed to read stdout: too much\ndata\"`. The default value of the `max_size` argument is 128 KB.\n\nUpon terminating successfully (with a zero exit status), `ok` will be `true`,\n`reason` will be `\"exit\"`, and `status` will hold the sub-process exit status.\n\nUpon terminating abnormally (non-zero exit status), `ok` will be `false`,\n`reason` will be `\"exit\"`, and `status` will hold the sub-process exit status.\n\nUpon exceeding a timeout threshold or any other unexpected error, `ok` will be\n`nil`, and `reason` will be a string describing the error.\n\nWhen a timeout threshold is exceeded, the sub-process will be terminated as\nsuch:\n\n1. first, by receiving a `SIGTERM` signal from this library,\n2. then, after 1ms, by receiving a `SIGKILL` signal from this library.\n\nNote that child processes of the sub-process (if any) will not be terminated.\nYou may need to terminate these processes yourself.\n\nWhen the sub-process is terminated by a UNIX signal, the `reason` return value\nwill be `\"signal\"` and the `status` return value will hold the signal number.\n\n[Back to TOC](#table-of-contents)\n\nDependencies\n============\n\nThis library depends on\n\n* the [lua-resty-signal](https://github.com/openresty/lua-resty-signal) library.\n* the [ngx.pipe](https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/pipe.md#readme)\nAPI of OpenResty.\n* the [lua-tablepool](https://github.com/openresty/lua-tablepool) library.\n\n[Back to TOC](#table-of-contents)\n\nAuthor\n======\n\nYichun Zhang (agentzh) \u003cyichun@openresty.com\u003e\n\n[Back to TOC](#table-of-contents)\n\nCopyright \u0026 Licenses\n====================\n\nThis module is licensed under the BSD license.\n\nCopyright (C) 2018-2019, [OpenResty Inc.](https://openresty.com)\n\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n\n* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\n\n* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\n\n* Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\n[Back to TOC](#table-of-contents)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenresty%2Flua-resty-shell","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenresty%2Flua-resty-shell","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenresty%2Flua-resty-shell/lists"}