{"id":18351615,"url":"https://github.com/anaisbetts/spawn-rx","last_synced_at":"2025-05-15T20:04:29.697Z","repository":{"id":40957083,"uuid":"54443793","full_name":"anaisbetts/spawn-rx","owner":"anaisbetts","description":"Observable and Promise versions of child_process.spawn","archived":false,"fork":false,"pushed_at":"2025-02-10T20:59:53.000Z","size":354,"stargazers_count":141,"open_issues_count":3,"forks_count":10,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-13T21:29:58.859Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/anaisbetts.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2016-03-22T03:57:19.000Z","updated_at":"2025-05-04T08:29:27.000Z","dependencies_parsed_at":"2024-12-05T09:31:00.463Z","dependency_job_id":"0b8c75f2-4a67-4864-8d20-53c33328e0c9","html_url":"https://github.com/anaisbetts/spawn-rx","commit_stats":{"total_commits":72,"total_committers":7,"mean_commits":"10.285714285714286","dds":0.3055555555555556,"last_synced_commit":"63c5d63d13f25a2c933edb826893e6ca12abc410"},"previous_names":["paulcbetts/spawn-rx"],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anaisbetts%2Fspawn-rx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anaisbetts%2Fspawn-rx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anaisbetts%2Fspawn-rx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anaisbetts%2Fspawn-rx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anaisbetts","download_url":"https://codeload.github.com/anaisbetts/spawn-rx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254414499,"owners_count":22067272,"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-11-05T21:32:06.541Z","updated_at":"2025-05-15T20:04:23.035Z","avatar_url":"https://github.com/anaisbetts.png","language":"TypeScript","funding_links":[],"categories":["Packages"],"sub_categories":[],"readme":"# spawn-rx: A better version of spawn\n\n| Linux/OSX | Windows |\n| --- | --- |\n| [![Build Status](https://travis-ci.org/tools-rx/spawn-rx.svg?branch=master)](https://travis-ci.org/tools-rx/spawn-rx) | [![Build status](https://ci.appveyor.com/api/projects/status/xm9xpgma4jwy3xns?svg=true)](https://ci.appveyor.com/project/dfbaskin/spawn-rx) |\n\n`spawn-rx` is a package that adds an Observable as well as a Promise version of \nthe `child_process.spawn` API, and fixes some deficiencies in `spawn` that come \nup especially on Windows. For example:\n\n* `spawn` searches PATH on POSIX platforms but will not on Windows, you need to\n  provide an exact path. spawn-rx makes Windows act like other platforms.\n  \n* On Windows, `{detached: true}` doesn't actually create a process group properly.\n  `spawn-rx` provides a `spawnDetached` method that allows you to spawn a detached\n  process and kill the entire process group if needed.\n  \n* POSIX platforms allow you to directly execute scripts that have a shebang at \n  the top of the file, whereas Windows can only natively `spawn` EXE files, which\n  makes executing npm binaries annoying. `spawn-rx` automatically rewrites your\n  `cmd` and `args` parameters for CMD scripts, PowerShell scripts, and node.js\n  files.\n\n## Examples\n\nspawn-as-promise:\n\n```js\n// Will run down path to find C:\\Windows\\System32\\wmic.exe, whereas normal \n// 'spawn' would require an absolute path.\nspawnPromise('wmic', [])\n  .then((result) =\u003e console.log(result));\n```\n\nHandle failed processes as errors:\n\n```js\ntry {\n  await spawnPromise('exit', ['-1']);\n} catch (e) {\n  console.log(\"Processes that return non-zero exit codes throw\")\n}\n```\n\nKill running process trees:\n\n```js\nlet disp = spawnDetached('takesALongTime', []).subscribe();\nawait Promise.delay(1000);\n\n// Kill the process and its children by unsubscribing.\ndisp.dispose();\n```\n\nStream process output:\n\n```js\nspawn('ls', ['-r'])\n  .subscribe(\n    (x) =\u003e console.log(x), \n    (e) =\u003e console.log(\"Process exited with an error\"));\n```\n\nExecute scripts:\n\n```js\n// Executes ./node_modules/.bin/uuid.cmd on Windows if invoked via `npm run`\nlet result = await spawnPromise('uuid');\n```\n\n\n## What's Jobber?\n\nJobber is a Windows executable that will execute a command in a process group,\nand if signaled via a named pipe, will terminate that process group. It's used\nin the implementation of `spawnDetached`. Jobber was written by me, and its license\nis the same as `spawn-rx`, it is not a third-party dependency.\n\n## Spawn output\n\nBy default spawn will merge stdout and stderr into the returned observable.\nYou can exclude one or the other by passing `ignore` in the `stdio` option of spawn.\n\nAlternatively if you call it with `{ split: true }` option, the observable output\nwill be an object `{ source: 'stdout', text: '...' }` so you can distinguish\nthe outputs.\n\n## Stdin support\n\nIf you provide an `Observable\u003cstring\u003e` in `opts.stdin`, it'll be subscribed upon\n and fed into the child process stdin. Its completion will terminate stdin stream.\n\n## Methods\n\n```typescript\n/**\n * Spawns a process attached as a child of the current process.\n *\n * @param  {string} exe               The executable to run\n * @param  {string[]} params     The parameters to pass to the child\n * @param  {SpawnOptions \u0026 SpawnRxExtras} opts              Options to pass to spawn.\n *\n * @return {Observable\u003cOutputLine\u003e}       Returns an Observable that when subscribed\n *                                    to, will create a child process. The\n *                                    process output will be streamed to this\n *                                    Observable, and if unsubscribed from, the\n *                                    process will be terminated early. If the\n *                                    process terminates with a non-zero value,\n *                                    the Observable will terminate with onError.\n */\nfunction spawn(\n  exe: string,\n  params: string[],\n  opts: SpawnOptions \u0026 SpawnRxExtras \u0026 { split: true }\n): Observable\u003cOutputLine\u003e;\n\nfunction spawn(\n  exe: string,\n  params: string[],\n  opts?: SpawnOptions \u0026 SpawnRxExtras \u0026 { split: false | undefined }\n): Observable\u003cstring\u003e;\n\n/**\n * Spawns a process but detached from the current process. The process is put\n * into its own Process Group.\n *\n * @param  {string} exe               The executable to run\n * @param  {string[]} params     The parameters to pass to the child\n * @param  {SpawnOptions \u0026 SpawnRxExtras} opts              Options to pass to spawn.\n *\n * @return {Observable\u003cOutputLine\u003e}       Returns an Observable that when subscribed\n *                                    to, will create a detached process. The\n *                                    process output will be streamed to this\n *                                    Observable, and if unsubscribed from, the\n *                                    process will be terminated early. If the\n *                                    process terminates with a non-zero value,\n *                                    the Observable will terminate with onError.\n */\nfunction spawnDetached(\n  exe: string,\n  params: string[],\n  opts: SpawnOptions \u0026 SpawnRxExtras \u0026 { split: true }\n): Observable\u003cOutputLine\u003e;\n\nfunction spawnDetached(\n  exe: string,\n  params: string[],\n  opts?: SpawnOptions \u0026 SpawnRxExtras \u0026 { split: false | undefined }\n): Observable\u003cstring\u003e;\n\n/**\n * Spawns a process as a child process.\n *\n * @param  {string} exe               The executable to run\n * @param  {string[]} params     The parameters to pass to the child\n * @param  {SpawnOptions \u0026 SpawnRxExtras} opts              Options to pass to spawn.\n *\n * @return {Promise\u003c[string, string]\u003e}       Returns a Promise that represents a child\n *                                 process. The value returned is the process\n *                                 output. If the process terminates with a\n *                                 non-zero value, the Promise will resolve with\n *                                 an Error.\n */\nfunction spawnPromise(\n  exe: string,\n  params: string[],\n  opts: SpawnOptions \u0026 SpawnRxExtras \u0026 { split: true }\n): Promise\u003c[string, string]\u003e;\n\nfunction spawnPromise(\n  exe: string,\n  params: string[],\n  opts?: SpawnOptions \u0026 SpawnRxExtras\n): Promise\u003cstring\u003e;\n\n/**\n * Spawns a process but detached from the current process. The process is put\n * into its own Process Group.\n *\n * @param  {string} exe               The executable to run\n * @param  {string[]} params     The parameters to pass to the child\n * @param  {SpawnOptions \u0026 SpawnRxExtras} opts              Options to pass to spawn.\n *\n * @return {Promise\u003c[string, string]\u003e}       Returns a Promise that represents a detached\n *                                 process. The value returned is the process\n *                                 output. If the process terminates with a\n *                                 non-zero value, the Promise will resolve with\n *                                 an Error.\n */\nfunction spawnDetachedPromise(\n  exe: string,\n  params: string[],\n  opts: SpawnOptions \u0026 SpawnRxExtras \u0026 { split: true }\n): Promise\u003c[string, string]\u003e;\n\nfunction spawnDetachedPromise(\n  exe: string,\n  params: string[],\n  opts?: SpawnOptions \u0026 SpawnRxExtras\n): Promise\u003cstring\u003e;\n\n/**\n * Finds the actual executable and parameters to run on Windows. This method\n * mimics the POSIX behavior of being able to run scripts as executables by\n * replacing the passed-in executable with the script runner, for PowerShell,\n * CMD, and node scripts.\n *\n * This method also does the work of running down PATH, which spawn on Windows\n * also doesn't do, unlike on POSIX.\n *\n * @param  {string} exe           The executable to run\n * @param  {string[]} args   The arguments to run\n *\n * @return {Object}               The cmd and args to run\n * @property {string} cmd         The command to pass to spawn\n * @property {string[]} args The arguments to pass to spawn\n */\nfunction findActualExecutable(\n  exe: string,\n  args: string[]\n): {\n  cmd: string;\n  args: string[];\n};\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanaisbetts%2Fspawn-rx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanaisbetts%2Fspawn-rx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanaisbetts%2Fspawn-rx/lists"}