찾다

 >  Q&A  >  본문

node.js - node的child_process.spawn(...[, options])怎么写多个options?

如果有多个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中文网2866일 전664

모든 응답(2)나는 대답할 것이다

  • 天蓬老师

    天蓬老师2017-04-17 15:38:29

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

    으아악

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

    으아악

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

    회신하다
    0
  • 天蓬老师

    天蓬老师2017-04-17 15:38:29

    예시에는 grep이 없나요?

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

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

    으아아아

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

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

    으아아아

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

    회신하다
    0
  • 취소회신하다