Node
Error: spawn yarn install ENOENT
该错误由于 命令 无效,因为 yarn 是 command 名称,install 是参数,所以需要单独传递。
另外也可以通过传递配置 shell: true,使 spawn 自行根据系统默认识别 shell 语法。
const install = spawn('yarn', ['install', '--force'], { stdio: 'inherit', cwd, shell: true });
spawn 与 exec
https://stackoverflow.com/questions/48698234/node-js-spawn-vs-execute
spawn 用于处理长数据,返回流,外部自行处理。
exec 有默认数据大小限制(200k),将返回数据 buffer,结束后返回 buffer。
- child process created by
spawn()
- does not spawn a shell
- streams the data returned by the child process (data flow is constant)
- has no data transfer size limit
child process created by
exec()
- does spawn a shell in which the passed command is executed
- buffers the data (waits till the process closes and transfers the data in on chunk)
- maximum data transfer 200kb (by default) ```javascript async function yarnInstall(cwd?: string) { const installCmd = spawn(‘yarn’, [‘install’, ‘—force’], { stdio: ‘inherit’, cwd, });
return new Promise((resolve, reject) => { installCmd.on(‘exit’, function (code) {
resolve(code);
}); });
// exec( // ‘yarn install’, // { // cwd, // }, // (error, stdout, stderr) => { // yarnDebug(‘yarn start’); // stdout.on(‘data’, function (data) { // process.stdout.write(data); // });
// if (error !== null) { // yarnDebug(‘yarn install err: %O’, error); // } // } // ); }
<a name="Dm9WC"></a>
# Sehll
<a name="VFkts"></a>
## 管道
获取环境变量并逐行打印 -> 筛选含public行 -> 打印结果行数
```shell
export | grep public | wc -l
JavaScript
console Error
console.log 打印错误时,是会打印栈信息的
console.error 则只会打印 message