convert popen to fopen call