I've been implementing a small program that executes a given command using execvp(). It works fine when not using redirection, but when I run a command such as:
cat file1.txt > redirected.txt
cat outputs the following error messages and fails:
cat: >: No such file or directory
cat: redirected.txt: No such file or directory
I've done some digging around and I'm starting to think that perhaps execvp() isn't allowed to do redirection because it doesn't run in the shell. Does that mean that I would have to manually pick out when redirection occurs and use pipes in my fork/exec code to get around this restriction? Is there a better way than to use execvp()?
Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…