Open k1mgy opened 5 years ago
I am not sure if this helps or not, but seems to work ok.
int main( int argc, char *argv[] ) {
sds tokens; int count, j; FILE fp; char path[10350];
/ Open the command for reading. / fp = popen("/usr/bin/find /home/user/Desktop/|tr '/' '_'", "r"); if (fp == NULL) { printf("Failed to run command\n" ); exit(1); }
/ Read the output a line at a time - output it. / while (fgets(path, sizeof(path)-1, fp) != NULL) { { sds y = sdsnew(path); printf("%s",y); sds line = sdsnew(y); tokens = sdssplitlen(line,sdslen(line),"home_user",9,&count); for (j = 0; j < count; j++) printf("%s\n", tokens[j]); sdsfreesplitres(tokens,count); }}
/ close / pclose(fp); return 0; }
Thank you for a fantastic library!!
One minor possible issue:
I am using sdssplitlen() to parse out the elements of a path+file string, as in: /DIR1/DIR2/this_isafile.txt <-- cTempString
tokens = sdssplitlen(cTempString,sdslen(cTempString),"/",1,&count);
With an underscore in the string, sdssplitlen() returns NULL.
Haven't single-step debugged it yet. For now, avoiding using filenames with _