home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!ferkel.ucsb.edu!taco!rock!stanford.edu!agate!spool.mu.edu!sgiblab!sgigate!sgi!wdl1!wdl39!mab
- From: mab@wdl39.wdl.loral.com (Mark A Biggar)
- Subject: Re: Bug or feature ?
- Message-ID: <1992Nov9.184724.4240@wdl.loral.com>
- Sender: news@wdl.loral.com
- Organization: Loral Western Development Labs
- References: <CONS.92Nov9103421@mercury.cern.ch>
- Distribution: comp
- Date: Mon, 9 Nov 1992 18:47:24 GMT
- Lines: 31
-
- In article <CONS.92Nov9103421@mercury.cern.ch> cons@mercury.cern.ch (Lionel Cons) writes:
- >I want to read the first two bytes of STDIN and then exec another
- >process that uses the remaining chars from STDIN. According to the man
- >pages the following script should work (if STDIN does not have the
- >close-on-exec flag set):
- >#!/usr/local/bin/perl
- >$c1 = getc(STDIN);
- >$c2 = getc(STDIN);
- >print "First chars: '$c1' and '$c2'\n";
- >exec('/bin/wc', '-c');
- >It does not work (wc reply is 0), why ?
-
- BUFFERING
-
- getc uses stdio, so when you did the first getc, stdio slurped in at least
- the whole first line into the buffer maybe more. You are going to have to use
- sysread to do what you want. E.G.
-
- #!/usr/local/perl
- sysread(STDIN,$c1,1);
- sysread(STDIN,$c2,1);
- print "First chars: '$c1' and '$c2'\n";
- exec('/bin/wc', '-c');
-
- --
- Perl's Maternal Uncle
- Mark Biggar
- mab@wdl1.wdl.loral.com
-
-
-
-