Skip to content

Instantly share code, notes, and snippets.

@banyudu
Created April 17, 2021 07:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save banyudu/f8d69386e52340c302dcde69cb223d0f to your computer and use it in GitHub Desktop.
Save banyudu/f8d69386e52340c302dcde69cb223d0f to your computer and use it in GitHub Desktop.
Node.js中spawn子进程继承Shell中的颜色等信息
const { spawn } = require('child_process')
const params = ['--someoption=somevalue', 'subcommand', 'any other params']
const myCmd = spawn('command-name', params, { stdio:'inherit' })
// 加上 { stdio:'inherit' } 选项之后,子进程会接管父进程的标准输入输出,这样console中的表现就和直接执行子进程相同,而不会丢失颜色、清屏等信息了
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment