How to use execv system call in linux?

后端 未结 2 561
心在旅途
心在旅途 2021-01-05 22:26

I am writing a program using execl to execute my exe file which is testing and it\'s work very well and display the output in the Linux CLI. But I have not idea how to chang

2条回答
  •  攒了一身酷
    2021-01-05 23:14

    In order to see the difference between execl and execv, here is a line of code executing a

    ls -l -R -a

    with execl :

    execl("/bin/ls", "ls", "-l", "-R", "-a", NULL);
    

    with execv :

    char* arr[] = {"ls", "-l", "-R", "-a", NULL};
    execv("/bin/ls", arr);
    

    The array of char* sent to execv will be passed to /bin/ls as argv (in int main(int argc, char **argv))

    Here is the execl(3) Linux manual page for more detail.

提交回复
热议问题