2016-09-06 1 views
1

nodejs (예 : rm, cp, mkdir 등)를 사용하여 쉘 스크립트 명령을 실행하는 데 유용한 라이브러리를 찾으려고합니다. 가능한 패키지에 대한 최근의 명확한 기사는 없습니다. 나는 exec-sync에 대해 많이 읽었습니다. 그러나 일부 사람들은 비추천적이라고 말합니다. 진실로 나는 길을 잃었고 아무 것도 찾을 수 없었다. exec-sync 설치를 시도했지만 다음 오류가 발생했습니다.nodejs를 사용하여 쉘 스크립트 명령을 실행하십시오.

npm ERR! [email protected] install: `node-gyp rebuild` 
npm ERR! Exit status 1 
npm ERR! 
npm ERR! Failed at the [email protected] install script 'node-gyp rebuild'. 

의견이 있으십니까?

+0

해보십시오 FS-추가 : https://www.npmjs.com/package/fs-extra – datafunk

답변

3

노드 하위 프로세스 핵심 모듈을 사용하거나 최소한 자신의 모듈을 빌드하는 데 사용할 수 있습니다.

Child Process

The child_process module provides the ability to spawn child processes in a manner that is similar, but not identical, to popen(3). This capability is primarily provided by the child_process.spawn() function:

특히 exec() 방법.

child_process.exec()

spawns a shell and runs a command within that shell, passing the stdout and stderr to a callback function when complete.

다음은 문서의 예제입니다.

Spawns a shell then executes the command within that shell, buffering any generated output.

const exec = require('child_process').exec; 
exec('cat *.js bad_file | wc -l', (error, stdout, stderr) => { 
    if (error) { 
    console.error(`exec error: ${error}`); 
    return; 
    } 
    console.log(`stdout: ${stdout}`); 
    console.log(`stderr: ${stderr}`); 
}); 
+0

는 간부의 동기 버전이 있습니까? –

+0

'child_process.execSync (command [, options])';) – DavidDomain