use popen3 instead of spawn
add last line