[ale]Stupid pipe question

Chris Fowler cfowler at outpostsentinel.com
Fri Nov 30 16:24:10 EST 2001


I'm trying to implement a simple pipe to more in a shell I'm creating.  I ahve some test code below 
vut is seems not to behave the way I expect.  It appears more does some
ioctls() on stdin which in my code is really a pipe.  What is the correct way I should do this?

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



int
main(int argc, char *argv[])
{
	int pfd[2];
	int pid;
	char buffer[1024];


	pipe(pfd);

	pid = fork();

	if(pid == 0)
	{
		close(pfd[1]);
		dup2(pfd[0], 0);
		read(0, buffer, sizeof(buffer));
		execl("/bin/more", "/bin/more", 0);
		perror("exec");
		exit(0);

	}
	
	close(pfd[0]);
	dup2(pfd[1], 1);
	while(read(0, buffer, sizeof(buffer)) > 0)
		write(1, buffer, strlen(buffer));



	return 0;
}
	




---
This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be 
sent to listmaster at ale dot org.






More information about the Ale mailing list