#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>

main()   {
	int pid,fd;
	printf("This is to show how to redirect!\n");
	if((pid=fork())==-1)   {
		perror("fork");
		exit(1);
	}
	else if(pid==0)
	{
		close(1);
		fd=creat("list.txt",0644);
		if(execlp("ls","ls","-l",NULL)<0)  {
			perror("exec");
			exit(1);
		}
	}
	else if(pid!=0)  {
		wait(NULL);
		system("cat list.txt");
	}
}
