BUT2/SCR/TP05/ex1.2.c

25 lines
435 B
C
Raw Normal View History

2023-10-23 13:07:05 +02:00
#define _GNU_SOURCE
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>
// ls -i -l /tmp >> log
//
int main(int argc, char *argv[])
{
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;
}