bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] problem on Using getline from a Coprocess


From: John Haque
Subject: Re: [bug-gawk] problem on Using getline from a Coprocess
Date: Sat, 12 Nov 2011 08:18:39 -0600
User-agent: Mutt/1.4.2.2i

Hi.

The answer can be found in the documentation that comes with gawk.
Please read the section two-way I/O; If 'info gawk' does not work
for you, you can produce the documentation in other formats using
gawk.texi in the doc subdirectory of the source distribution.

You need to explicitely close the pipe or the write end
of the two-way process.

On Wed, Nov 09, 2011 at 09:55:03PM +0800:
> i want to try "Using getline from a Coprocess" but i got a error,
> 21:37:43#tp#~> cat a.awk
> #!/usr/bin/awk
> {print $0 | "base64"
> }

This works because gawk closes the pipe for you when it exits. Try
these two versions and see the difference:

{
        print $0 | "base64"
        close("base64")
        print "gawk"
}

vs.

{
        print $0 | "base64"
        print "gawk"
}


> 21:37:47#tp#~> cat b.awk
> #!/usr/bin/awk
> {print $0 |& "base64"
> "base64"|&getline a
> print a}

You need to tell "base64" that no more input is coming:

{print $0 |& "base64"
close("base64", "to")   # closes the write end
"base64"|& getline a
print a}


Thanks,

John

> 21:37:51#tp#~> echo abc|awk -f a.awk
> YWJjCg==
> 21:37:55#tp#~> awk --version|head -n2
> GNU Awk 3.1.6
> Copyright (C) 1989, 1991-2007 Free Software Foundation.
> 21:38:07#tp#~> echo abc|awk -f b.awk
> ^C       #here it won't stop, so i have to use CTRL+C to stop it.
> 21:38:16#tp#~>
> any help is appreciated.
> -- 
> contact me:
> MSN: address@hidden
> GTALK: address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]