Redirection inside call to execvp() not working

后端 未结 3 707
既然无缘
既然无缘 2020-12-09 23:55

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:

<         


        
3条回答
  •  执笔经年
    2020-12-10 00:38

    It seems like the easiest thing to do is:

    execlp( "/bin/sh", "/bin/sh", "-c", "cat file1.txt > redirected.txt", (char *)NULL );
    

    You can do the same with execvp.

提交回复
热议问题