import {execa} from'execa';
// Similar to `echo unicorns > stdout.txt` in Bashawaitexeca('echo', ['unicorns']).pipeStdout('stdout.txt');
// Similar to `echo unicorns 2> stdout.txt` in Bashawaitexeca('echo', ['unicorns']).pipeStderr('stderr.txt');
// Similar to `echo unicorns &> stdout.txt` in Bashawaitexeca('echo', ['unicorns'], {all: true}).pipeAll('all.txt');
重定向文件中的输入
import {execa} from'execa';
// Similar to `cat < stdin.txt` in Bashconst {stdout} = awaitexeca('cat', {inputFile: 'stdin.txt'});
console.log(stdout);
//=> 'unicorns'
保存子进程的输出并通过管道传递
import {execa} from'execa';
const {stdout} = awaitexeca('echo', ['unicorns']).pipeStdout(process.stdout);
// Prints `unicorns`console.log(stdout);
// Also returns 'unicorns'
管道多工序
import {execa} from'execa';
// Similar to `echo unicorns | cat` in Bashconst {stdout} = awaitexeca('echo', ['unicorns']).pipeStdout(execa('cat'));
console.log(stdout);
//=> 'unicorns'