in reply to Capturing remote command output to a file

It seems you were trying to use system safely by avoiding the shell by using it's multi-argument form, then abandoned your efforts and introducing other errors in the process. Solutions: