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
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…