문제

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!

도움이 되었습니까?

해결책

You can change PATH with setenv -- but mind you, it might be simpler to just check for those commands explicitly before doing the exec.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top