c - execvp - ls: fts_open: No such file or directory -
i'm struggling error. i'm writing shell emulator, using fork() executing command using execvp();. every command try parse shell working perfectly, except ls without arguments. if try execute ls -lah, works, simple ls won't, receiving following error:
ls: fts_open: no such file or directory
here snippet of code: (just essential)
pid = fork(); if (pid==0) { puts("child"); puts(args[0]); puts(args[1]); printf("%d\n", strlen(args[1])); args[2] = null; execvp(args[0], args); } else wait(null); puts("back parent"); }
and here output ls:
ls child ls 0 ls: fts_open: no such file or directory parent
as can see, args[0] contains ls, args[1] empty, there no arguments, length of args[1] 0, keep getting error.
any idea on be?
edit:
kudos jonathan leffler finding out: (also, seems issue on mac)
the point args[1] not empty, so, os tries open '' file, which, obviously, not exists, and, looks, can't created, since not name.
so, here did: check len of args[1]. if 0, set null. (just freeing memory did not helped)
pid = fork(); if (pid==0) { puts("child"); puts(args[0]); puts(args[1]); if (strlen(args[1]) == 0) args[1] = 0; args[2] = null; execvp(args[0], args); } else wait(null); puts("back parent"); }
if there no more arguments, pointer should null, not non-null pointer 0 length string.
pid = fork(); if (pid==0) { puts("child"); puts(args[0]); fflush(stdout); args[1] = 0; execvp(args[0], args); fprintf(stderr, "failed exec %s\n", args[0]); exit(1); } else wait(null); puts("back parent");
just out of pure curiosity, tried @ command line:
$ ls '' ls: fts_open: no such file or directory $
are running on mac too? (to surprised see same message doesn't begin describe reaction!) what's more intriguing creating file fts_open
doesn't seem rid of error message. weird behaviour ls
, in response invalid request (there no file names empty string).
Comments
Post a Comment