2

I called "ls" command using the execvp system call from inside a c file. But there seems to be a slight difference.

enter image description here

The exe files in the default ls call are highlighted green But not in my own execvp ls call. Am I missing something?

This is the piece of code that is calling ls.

else if (rc == 0) 
{ 
    // child (new process)
    printf("hello, I am child (pid:%d)\n", (int) getpid());
    char *myargs[2];
    myargs[0] = strdup("ls");
    // program: "wc" (word count)
    myargs[1] = NULL;//strdup("p3.c"); // argument: file to count
    //myargs[2] = NULL;
    // marks end of array
    execvp(myargs[0], myargs); // runs word count
    printf("this shouldn’t print out");
}
muru
  • 207,228
Alchemist
  • 203

1 Answers1

4

ls in your shell is an alias to ls --color=auto:

$ alias ls
alias ls='ls --color=auto'

If you want the colouring in ls output, use the --color option.

muru
  • 207,228