I'm currently using execvp() for my lab program and I realise that the
first argument (args[0]) I pass to execvp is always not passed to the
file ("/bin/ls") being executed.
I'm using gcc compiler (3.3.1) running under Cygwin from Redhat.
I've done a test program which looks like this:
main(){
char* args[3];
args[0] = "--color=auto";
args[1] = "-l";
args[2] = NULL;
execvp("/bin/ls", args);
}
The purpose of the --color=auto switch is to enable a color listing of
the files and directories. As it turns out, the output is the same as
/bin/ls -l. Minus the --color=auto.
main(){
char* args[4];
args[0] = "-dummy";
args[1] = "--color=auto";
args[2] = "-l";
args[3] = NULL;
execvp("/bin/ls", args);
}
If I add in a dummy for the first argument (-dummy at args[0]) then
the output is equivalent to /bin/ls --color=auto -l. Minus the -dummy.
We can see that args[0] is always not passed to /bin/ls.
Is this a bug or is my understanding of exec* parameters wrong? Why is
this happening?
---
Goh, Yong Kwang
Singapore