Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
114 views
in Technique[技术] by (71.8m points)

javascript - Node.js Spawn vs. Execute

In an online training video I am watching to learn Node, the narrator says that "spawn is better for longer processes involving large amounts of data, whereas execute is better for short bits of data."

Why is this? What is the difference between the child_process spawn and execute functions in Node.js, and when do I know which one to use?

question from:https://stackoverflow.com/questions/48698234/node-js-spawn-vs-execute

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The main difference is the spawn is more suitable for long-running process with huge output. spawn streams input/output with child process. exec buffered output in a small (by default 200K) buffer. Also as I know exec first spawn subshell, then try to execute your process. To cut long story short use spawn in case you need a lot of data streamed from child process and exec if you need such features as shell pipes, redirects or even you need exec more than one program in one time.

Some useful links - DZone Hacksparrow


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...