node.js - node的child_process.spawn(...[, options])怎么写多个options?
PHP中文网
PHP中文网 2017-04-17 15:36:29
0
2
667

如果有多个grep,怎么写到上面的语句中?例如cat /dev/urandom |od -x|tr -d ' '|head -n 1

在网上找了下,发现用以下的方法也行,使用spawnexec有什么区别呢?

const exec = require('child_process').exec;
exec('cat /dev/urandom |od -x|tr -d ' '|head -n 1', (error, stdout, stderr) => {
  if (error) {
    console.error(`exec error: ${error}`);
    return;
  }
  console.log(`stdout: ${stdout}`);
  console.log(`stderr: ${stderr}`);
});
PHP中文网
PHP中文网

认证0级讲师

모든 응답(2)
Peter_Zhu

캡슐화되지 않은 경우 여러 이벤트를 수신해야 합니다. 예를 들어 cat /dev/urandom |od -x|tr -d ' '|head -n 1

으아악

spwan이 다음과 같이 하위 프로세스를 생성할 때 파이프를 지정할 수도 있습니다

으아악

실제 환경에서는 stderr에 대한 정보를 처리해야 합니다

Peter_Zhu

예시에는 grep이 없나요?

https://nodejs.org/api/child_...

여러 옵션이 배열 형식의 두 번째 매개변수로 전달됩니다: ls -lh /usr

으아아아

당신이 제시한 예cat /dev/urandom |od -x|tr -d ' '|head -n 1

스크린샷을 찍은 파이프라인을 따르고 별도로 수행하세요.

으아아아

파이프라인의 경우 스크린샷 예시에 어떻게 작성되어 있는지 확인하세요. 콜백에서 다음 명령이 실행되는 방식입니다.

최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿