Actually, SO showed a link on the side right after I posted showing the correct answer, I guess I did not look hard enough:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tcl8.5/expect.h>
#include <errno.h>
int main()
{
char str[512];
FILE *f = exp_popen("ssh user@mybox ls -lR");
if (f==NULL)
{
printf("Failed (%s)\n", strerror(errno));
return 1;
}
while(fgets(str, sizeof(str)-1, f))
{
printf("%s", str);
}
return 0;
}
(Taken from How to read stdout from a FILE* created with libexpect in C++ on linux?)