I have an array of command strings I want to execute by calling execvp()
:
char* commands[] = ["ls -l", "ps -a", "ps"];
char* command = commands[0];
...
How do I execute the command with execvp
?
I have an array of command strings I want to execute by calling execvp()
:
char* commands[] = ["ls -l", "ps -a", "ps"];
char* command = commands[0];
...
How do I execute the command with execvp
?
Here's a possible usage example for you. This takes the command to execute from its arguments or you can uncomment the hardcoded example.
I recommend you look up the used commands in their respective man pages. For
execvp
, the declaration isargv[0]
should be the same asfile
by convention andargv
should beNULL
-terminated.