spawn: reshuffle code to get proper stdin for spawned process