I have a simple program where I take in a command and call execve()
to execute the command. I run into this problem where
sortedCmd[100][100];
status = execve(sortedCmd[0],sortedCmd, envp);
will not work (strerror(errno) = No such file or directory
), however, the following code work
status = execve(sortedCmd[0],(char *[]){sortedCmd[0], NULL}, envp);
I made sure there is a NULL
character there after the last parameter. I guess the problem is char *[]
and char[][]
. Is there a way to work around this? Since the program can take multiple arguments, I cannot just hardcode it. Please help me, thanks!