r305_dm/TP5/Exo1/exo1_2.c

20 lines
449 B
C
Raw Permalink Normal View History

2023-10-06 11:31:48 +02:00
#define _GNU_SOURCE
#include <fcntl.h>
2023-10-05 22:42:05 +02:00
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>
2023-10-06 11:31:48 +02:00
// ls -i -l /tmp >> log
//
2023-10-05 22:42:05 +02:00
int main(int argc, char *argv[])
{
2023-10-06 11:31:48 +02:00
int redirection = open("./log",O_WRONLY | O_APPEND | O_CREAT , 0644);
assert(redirection >= 0);
// dup2 ferme 1, et duplique redirection
dup2(redirection,1);
close(redirection);
execlp("ls","ls","-i","-l","/tmp",NULL);
assert(0);
return 0;
}