X-Git-Url: https://git.piment-noir.org/?p=TD_IML.git;a=blobdiff_plain;f=TD2%2Fexercise2%2Fexercise.c;fp=TD2%2Fexercise2%2Fexercise.c;h=ae5ed846e685c3ac4aa30ff9e9e7c47ac513b8db;hp=0000000000000000000000000000000000000000;hb=80b1633cbdb86828624f8b84399e10b340b398c6;hpb=d57668faea3e58be64bb9fbe8cde3c293ebb7990 diff --git a/TD2/exercise2/exercise.c b/TD2/exercise2/exercise.c new file mode 100644 index 0000000..ae5ed84 --- /dev/null +++ b/TD2/exercise2/exercise.c @@ -0,0 +1,23 @@ +#include +#include +#include +#include + +#include +#include + +int main() { + int out_file_fd = open("ouput.txt", O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR); + if (out_file_fd < 0) { + perror("open failure\n"); + exit(EXIT_FAILURE); + } + + dup2(out_file_fd, STDOUT_FILENO); + + execl("/bin/ls", "ls", (char*)NULL); + + close(out_file_fd); + + return EXIT_SUCCESS; +}