简体   繁体   中英

Run multiple commands from same node.js child process

Is there any way in node.js to fork a new process and run multiple terminal shell commands and execute node.js functions such as fs.writeFileSync from that same process/context.

As an example I want to do the following. Execute all the below in the same process.

exec("git worktree add -b"....);
exec("cd ../");
writeFileSync(...);

This is an express.js applcation, and because multiple users will be accessing the same filesystem at the same time and performing git actions on the same repo, I want to avoid conflicts by spawning a new process for each one.

Separate it out into a main hub that calls it's children. These children preform any writing/saving that you need to be multithreaded.

Just have the parent call exec("node myWritingChild.js"); when it needs to make one of these writing threads.

Please note: it is usually better to run a child via letting it open through a pipe/forking it. There are many postings about this so look it up if you want to. Also check out these docs .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM