[Node.js] Terminal 명령을 수행하는 node_cmd 모듈[Node.js] Terminal 명령을 수행하는 node_cmd 모듈
Posted at 2019. 5. 10. 16:22 | Posted in Node.js반응형
참고 : https://www.npmjs.com/package/node-cmd
■ 노드에서 터미널 명령 실행을 하게 해주는 node-cmd 모듈
node_cmd는 nodejs의 실행프로그램에서 터미널( or 명령프롬프트)에서 다른 node 모듈을 실행시킬 수 있다.
# node-cmd 설치
$ npm install node-cmd |
터미널 명령을 수행할 노드 실행 파일을 아래와 같이 생성한다.
# 소스 코드① - 터미널 명령 수행
node_cmd.js |
var cmd = require( "node-cmd" );
cmd.get( // 실행할 노드 실행 파일 "node console_log.js" , function( error, success, stderr ) { if( error ) { console.log( "ERROR 발생 :\n\n", error ); } else { console.log( "SUCCESS :\n\n", success ); } } ); |
다음으로 node_cmd.js 에서 실행할 node 실행파일을 하나더 만든다.
# 소스 코드② - 테스트 노드 파일
console_log.js |
console.log("do you guys not have phones"); |
# 실행 결과
$ node node_cmd.js |
|
반응형
'Node.js' 카테고리의 다른 글
[Node.js] Excel 파일 생성하고 데이터 읽기 (2) | 2020.05.01 |
---|---|
[Node.js] Serial Port를 이용한 Arduino 이벤트 실행 (0) | 2019.06.13 |
[Node.js] SCRAPING을 위한 cheerio 모듈과 cheerio-httpcli 모듈 (0) | 2019.05.08 |
[Node.js] node.js로 PDF 문서 생성하기 (2) | 2019.04.11 |
[Node.js] package.json과 npm i 명령 (0) | 2019.04.02 |