{"id":17383614,"url":"https://github.com/tsertkov/exec-sh","last_synced_at":"2025-04-04T16:13:38.481Z","repository":{"id":558133,"uuid":"20822497","full_name":"tsertkov/exec-sh","owner":"tsertkov","description":"node helper to execute shell commands","archived":false,"fork":false,"pushed_at":"2024-02-13T08:12:15.000Z","size":721,"stargazers_count":64,"open_issues_count":0,"forks_count":9,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T15:05:19.700Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/exec-sh","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tsertkov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-06-14T01:33:04.000Z","updated_at":"2025-02-05T18:07:31.000Z","dependencies_parsed_at":"2024-06-18T13:42:25.267Z","dependency_job_id":null,"html_url":"https://github.com/tsertkov/exec-sh","commit_stats":{"total_commits":65,"total_committers":6,"mean_commits":"10.833333333333334","dds":0.2153846153846154,"last_synced_commit":"11a181f641a8d36d2f9c7f16a438b6f8ad3a83e5"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsertkov%2Fexec-sh","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsertkov%2Fexec-sh/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsertkov%2Fexec-sh/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsertkov%2Fexec-sh/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tsertkov","download_url":"https://codeload.github.com/tsertkov/exec-sh/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247208139,"owners_count":20901570,"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-10-16T07:43:16.184Z","updated_at":"2025-04-04T16:13:38.459Z","avatar_url":"https://github.com/tsertkov.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# exec-sh\n\n[![NPM](https://nodei.co/npm/exec-sh.png)](https://nodei.co/npm/exec-sh/)\n[![NPM Downloads](https://img.shields.io/npm/dm/exec-sh.svg)](https://www.npmjs.com/package/exec-sh)\n\n\u003e Execute shell command forwarding all stdio streams.\n\n## Features\n\nexec-sh is a wrapper for [`child_process.spawn`](http://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options) with some improvements:\n\n- Cross platform command execution:\n  - Windows: `cmd /C COMMAND`\n  - others: `sh -c COMMAND`\n- Forwards all stdio streams to current terminal (by default):\n  - `execSh(\"bash\")`\n  - `execsh(\"echo -n Say: \u0026\u0026 read i \u0026\u0026 echo Said:$i\")`\n- stdout and stderr are passed to callback when available\n  - `execSh(\"pwd\", console.log)`\n\n## Showcase\n```javascript\n// JavaScript\n\nexecSh(\"echo hello exec-sh \u0026\u0026 bash\", { cwd: \"/home\" }, function(err){\n  if (err) {\n    console.log(\"Exit code: \", err.code);\n  }\n});\n```\n\n```sh\n# Terminal output: interactive bash session\n\nhello exec-sh\nbash-3.2$ pwd\n/home\nbash-3.2$ exit 99\nexit\nExit code:  99\n```\n\n## Usage\n\n```javascript\nconst execSh = require(\"../\");\n\n// run interactive bash shell\nexecSh(\"echo lorem \u0026\u0026 bash\", { cwd: \"/home\" }, (err) =\u003e {\n  if (err) {\n    console.log(\"Exit code: \", err.code);\n    return;\n  }\n\n  // collect streams output\n  const child = execSh([\"bash -c id\", \"echo lorem \u003e\u00262\"], true,\n    (err, stdout, stderr) =\u003e {\n      console.log(\"error: \", err);\n      console.log(\"stdout: \", stdout);\n      console.log(\"stderr: \", stderr);\n    });\n});\n```\n\n## Promise Interface\n\n```javascript\nconst execShPromise = require(\"exec-sh\").promise;\n\n// run interactive bash shell\nconst run = async () =\u003e {\n  let out;\n\n  try {\n    out = await execShPromise('pwd', true);\n  } catch (e) {\n    console.log('Error: ', e);\n    console.log('Stderr: ', e.stderr);\n    console.log('Stdout: ', e.stdout);\n\n    return e;\n  }\n\n  console.log('out: ', out.stdout, out.stderr);\n}\n\nrun();\n```\n\n## Public API\n\n### `execSh(command, [options], [callback])`\n\nExecute shell command forwarding all stdio.\n\n**Parameters:**\n\n- `command {String|Array}` - The command to run, or array of commands\n- `[options] {Object|TRUE}` - Options object passed directly to [`child_process.spawn`](http://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options), when `TRUE` then `{ stdio: null }` used\n- `[callback] {Function}` - `callback(err, stdout, stderr)`\n - `err {Error|NULL}` - Error object. Has `code` property containing last command exit code when available\n - `stdout {String|NULL}` - aggregated stdout or `NULL` if not available\n - `stderr {String|NULL}` - aggregated stderr or `NULL` if not available\n\n**Return Values:**\n\nReturns [ChildProcess](http://nodejs.org/api/child_process.html#child_process_class_childprocess) object.\n\n## Scripts\n\n- `npm test` - run tests\n- `npm run jsdoc` - build jsdoc\n- `npm run dev` - run tests continuously\n\n## License\n\nThe MIT License (MIT)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftsertkov%2Fexec-sh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftsertkov%2Fexec-sh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftsertkov%2Fexec-sh/lists"}