When calling the function, pass in the script path name or specific command.
int shell_call(std::string &cmdstr) {
enum { maxline=100 };
char line[maxline];
FILE *fpin;
int ret;
if((fpin = popen(cmdstr.c_str(), "r")) == NULL) {
printf("popen error\n");
exit(-1);
}
for(;;) {
if(fgets(line, maxline, fpin) == NULL)
break;
fputs("prompt> \n", stdout);
fflush(stdout);
if(fputs(line, stdout) == EOF) {
printf("fputs error\n");
exit(-1);
}
}
if((ret = pclose(fpin)) == -1) {
printf("pclose error\n");
exit(-1);
}
return ret;
}