Last active
January 6, 2023 06:50
-
-
Save dstyle0210/55b57498119f9f4514fcd8dcdd0018b4 to your computer and use it in GitHub Desktop.
윈도우,노드환경에서 스폰(spawn) 사용시 ENOENT 에러 지겹..
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // node , windows 에서 spawn 사용 기초 | |
| // 스토리북 연동 중, global storybook이 없는 케이스 (로컬에서만 돌려야 하는경우) | |
| // gulp 에서 즉시 실행이 불가함. (global에 없음 == storybook 다이렉트 실행 불가.) | |
| import { task } from "gulp"; // gulp4 | |
| import { spawn } from "child_process"; | |
| // 부모프로세서에서 로그를 함께 볼때 (자식 -> 부모 로 log 전파됨) | |
| task("test0", (done) => { | |
| const spawnProcess = spawn("npm",["run","storybook"],{ | |
| shell:true, // 이거 쉘코드임 (cmd 에서 실행하는거야.) | |
| stdio:"inherit" // 부모 프로세스와 동기화 할꺼야. (정확하겐 스폰된 자식프로세스에서 부모프로세스로 out시킴) | |
| }); | |
| // 이건 부모프로세스가 죽으면, 자식도 함께 죽음 (동기화) | |
| done(); | |
| }); | |
| // 별도의 CMD 창을 열고, 보고싶을때 (부모프로세서로 안날림.) | |
| task("test1", (done) => { | |
| const spawnProcess = spawn("npm",["run","storybook"],{ | |
| shell:true, // 이거 쉘코드임 (cmd 에서 실행하는거야.) | |
| detached:true, // 부모랑 자식이랑 헤어졌음 | |
| stdio:"ignore" // 혼자 놀꺼라고 선언함 | |
| }); | |
| spawnProcess.unref(); // 완전히 헤어졌다고 선언함(호적팜?) => 이렇게 해야, gulp 프로세스가 종료 됨 | |
| console.log( spawnProcess.pid ); // 나중에 혹시라도 process.kill 해야 할지 모르니 pid는 표시 | |
| done(); | |
| }); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment