redirecting output to a file in C

后端 未结 3 616
傲寒
傲寒 2020-12-06 03:10

i coded a basic shell in C for executing basic commands it\'ll execute commands ls, ls -al , ls -al | more etc.

i want to exec

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-06 03:31

    Before you call execve(2) in the newly created process to execute the command, you can redirect its standard input or output via the dup2(2) system call:

    /* redirect stdout to a file */
    dup2(1, some_open_file_descriptor);
    

    Of course, you need to have some error handling.

提交回复
热议问题