{"id":19859611,"url":"https://github.com/youngjuning/child_process","last_synced_at":"2026-06-10T12:31:12.243Z","repository":{"id":89684718,"uuid":"404627979","full_name":"youngjuning/child_process","owner":"youngjuning","description":"Nodejs child_process 模块使用案例","archived":false,"fork":false,"pushed_at":"2021-09-12T06:24:01.000Z","size":16,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-27T22:21:14.245Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/youngjuning.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":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-09-09T07:31:43.000Z","updated_at":"2023-05-04T11:51:27.000Z","dependencies_parsed_at":"2024-02-02T03:49:38.686Z","dependency_job_id":null,"html_url":"https://github.com/youngjuning/child_process","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/youngjuning/child_process","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/youngjuning%2Fchild_process","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/youngjuning%2Fchild_process/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/youngjuning%2Fchild_process/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/youngjuning%2Fchild_process/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/youngjuning","download_url":"https://codeload.github.com/youngjuning/child_process/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/youngjuning%2Fchild_process/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34153482,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-10T02:00:07.152Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-12T14:29:22.042Z","updated_at":"2026-06-10T12:31:12.209Z","avatar_url":"https://github.com/youngjuning.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003ch1\u003echild_process\u003c/h1\u003e\n  \u003cp\u003eNodejs 子进程使用案例\u003c/p\u003e\n\u003c/div\u003e\n\n## child_process\n\n### 执行 `yarn install`\n\n```js\nconst { spawnSync } = require('child_process');\n\nspawnSync(\"yarn install\",{\n  shell: true,\n  stdio: 'inherit'\n});\n```\n\n![image](https://user-images.githubusercontent.com/13204332/132640641-5cf686eb-1f62-48d5-99ef-93e76324f101.png)\n\n### 获取 `git config` 信息\n\n#### spawnSync\n\n- [How to read child_process.spawnSync stdout with stdio option 'inherit'](https://stackoverflow.com/questions/35689080/how-to-read-child-process-spawnsync-stdout-with-stdio-option-inherit)\n\n```js\nconst { spawnSync } = require('child_process');\nconst gitConfig = spawnSync(\"git config --get user.name\", {\n  stdio: 'pipe',\n  encoding: 'utf-8',\n  shell: true,\n})\nconsole.log(gitConfig.stdout.trim());\n```\n\n#### execSync\n\n- [vue-cli git-user.js](https://unpkg.com/browse/vue-cli@2.9.6/lib/git-user.js)\n\n```js\nconst { execSync } = require('child_process');\nconsole.log(gitConfig.stdout.trim());\n\nconst name = execSync('git config --get user.name')\nconsole.log(name.toString().trim());\n```\n\n## execa\n\n### 执行 `yarn install`\n\n\u003e 一个[小问题](https://github.com/sindresorhus/execa/issues/473)坑我很久。\n\n```js\nconst execa = require(\"execa\");\n\nexeca.commandSync('yarn install',{\n  stdout: \"inherit\",\n  stderr: \"inherit\",\n  shell: true,\n});\n```\n\n![image](https://user-images.githubusercontent.com/13204332/132640641-5cf686eb-1f62-48d5-99ef-93e76324f101.png)\n\n### 获取 `git config` 信息\n\n```js\nconst execa = require(\"execa\");\n\nconst {stdout: username} = execa.commandSync('git config --get user.name');\nconsole.log(username);\n```\n\n## exec-sh\n\n### 执行 `yarn install`\n\n```js\nconst execSh = require('exec-sh').promise;\n\n(async () =\u003e {\n  await execSh('yarn install',{\n    shell: true\n  })\n})()\n```\n\n![image](https://user-images.githubusercontent.com/13204332/132640641-5cf686eb-1f62-48d5-99ef-93e76324f101.png)\n\n## shelljs\n\n### 执行 `yarn install`\n\n\u003e 这是唯一一个不能满足需求的库，但是这个库的核心功能其实是封装了很多 shell 方法，但是也有点脱裤子放屁，我直接用 execa 也可以直接执行任何命令呀。\n\n```js\nconst shell = require(\"shelljs\");\nshell.exec(\"yarn install\");\n```\n\n![image](https://user-images.githubusercontent.com/13204332/132643279-58606264-f7f3-4fe1-a8b7-ca6b620fe1b6.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoungjuning%2Fchild_process","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyoungjuning%2Fchild_process","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoungjuning%2Fchild_process/lists"}