From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30643 invoked by alias); 1 Oct 2006 13:55:12 -0000 Received: (qmail 30634 invoked by uid 22791); 1 Oct 2006 13:55:11 -0000 X-Spam-Check-By: sourceware.org Received: from mailguard-send.adelaide.edu.au (HELO tosh.services.adelaide.edu.au) (192.43.227.21) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sun, 01 Oct 2006 13:55:10 +0000 Received: from ren.services.adelaide.edu.au ([10.0.10.11]) by tosh.services.adelaide.edu.au with ESMTP; 01 Oct 2006 23:25:07 +0930 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AQAAAGdlH0UN X-IronPort-AV: i="4.09,240,1157293800"; d="scan'208"; a="18827671:sNHT17965941" Received: from ren.services.adelaide.edu.au (localhost.localdomain [127.0.0.1]) by ren.services.adelaide.edu.au (8.13.1/8.13.1) with ESMTP id k91Ds367017826 for ; Sun, 1 Oct 2006 23:24:03 +0930 Received: (from apache@localhost) by ren.services.adelaide.edu.au (8.13.1/8.13.1/Submit) id k91Ds3nn017825 for gcc-help@gcc.gnu.org; Sun, 1 Oct 2006 23:24:03 +0930 Received: from 203-173-35-182.dyn.iinet.net.au (203-173-35-182.dyn.iinet.net.au [203.173.35.182]) by webmail.adelaide.edu.au (IMP) with HTTP for ; Sun, 1 Oct 2006 23:24:03 +0930 Message-ID: <1159710843.451fc87b708f8@webmail.adelaide.edu.au> Date: Sun, 01 Oct 2006 13:55:00 -0000 From: Owen Lucas To: gcc-help@gcc.gnu.org Subject: Problem piping stdout References: <1159709654.451fc3d67797a@webmail.adelaide.edu.au> In-Reply-To: <1159709654.451fc3d67797a@webmail.adelaide.edu.au> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit User-Agent: Internet Messaging Program (IMP) 3.2.6 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2006-10/txt/msg00005.txt.bz2 Im doing a program that reads in stuff from the serial port under linux. Once read in there is a bit of formatting and it then needs to get piped to something else. At the end is the cut down code. anyway the interesting part is in the while loop the rest is just formatting. while (1) { // read(fd,buf,50); printf("hello world\n"); } it prints out real fast to screen (as you would expect) and it can be piped to a file ./a.out > test.txt resulting in a large text file (as you would expect) now if the read(fd,buf,50); line is uncommented, it now only does printf("hello world\n") everytime a CR is reciveded on the serial port which terminates the read function (as it should). Now it displays to screen (as it should) but it does NOT pipe to file with ./a.out > test.txt. It creates a blank file but doesnt put anything in it. Why does a read function unrelated to STDIN or STDOUT in the code muck up a linux pipe?????? Got be baffled and dont know what to do now. Is this a GCC thing, a BASH thing or a linux thing Im lost on this one. Can anyone spot the problem (It probably is me but I cant see it) owen (appologies to the gcc@gcc.gnu.org where I may have accidently posted this. got a bit confused in the sign up process ie email from gcc-help-help@gcc.gnu.org for this list and gcc-help@gcc.gnu.org for the other one. I clicked the wrong post to. woops very sorry) ----- #include #include #include #define BAUDRATE B19200 #define MODEMDEVICE "/dev/ttyS0" #define _POSIX_SOURCE 1 /* POSIX compliant source */ main() { int fd; struct termios oldtio,newtio; char buf[50]; fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY ); if (fd <0) {perror(MODEMDEVICE); exit(-1); } tcgetattr(fd,&oldtio); /* save current serial port settings */ bzero(&newtio, sizeof(newtio)); /* clear struct for new port settings */ newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD; newtio.c_iflag = IGNPAR | ICRNL; newtio.c_oflag = 0; newtio.c_lflag = ICANON; tcflush(fd, TCIFLUSH); tcsetattr(fd,TCSANOW,&newtio); while (1) { // read(fd,buf,50); printf("hello world\n"); } tcsetattr(fd,TCSANOW,&oldtio); // restore the old port settings }