You can change PATH
with setenv
-- but mind you, it might be simpler to just check for those commands explicitly before doing the exec
.
Add directory to the PATH for execvp()
题
I am writing a small console-like program in C, along with implementations for ls, tac and dir.
I use execvp() function to override the forked children of the process, but when the user inserts one of the above 3 commands, I have to execute my own version, not the one from the system.
I know that execvp() uses the system PATH variable to search in different locations for the executable file. Can I somehow edit the PATH in my program, so I could add a custom directory as the first place for execvp() search?
Thank you!
解决方案
不隶属于 StackOverflow