Is there a simpler way/method to get the return value from a unix cmd then to use the following method:
FILE *in;
char cmd[5] = "pwd";
char buf[100];
in = popen(cmd, "r");
fgets(buf,100,in);
/* or use some form of fscanf(in,%s,buf); */
pclose(in);
It seems that "popen" is the only way to get the actual return value(s). I use this method when I need to process a lot of data, but when I know it's just a one line return value from a unix cmd (e.g. - pwd, date, some grep cmd etc.), it's just seems overkill to have to use popen and the FILE pointers.
FILE *in;
char cmd[5] = "pwd";
char buf[100];
in = popen(cmd, "r");
fgets(buf,100,in);
/* or use some form of fscanf(in,%s,buf); */
pclose(in);
It seems that "popen" is the only way to get the actual return value(s). I use this method when I need to process a lot of data, but when I know it's just a one line return value from a unix cmd (e.g. - pwd, date, some grep cmd etc.), it's just seems overkill to have to use popen and the FILE pointers.