use popen for external programs; do some more error checking; give correct error messages