[Top][All Lists]

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

Coproc usage ... not understanding

From: Linda Walsh
Subject: Coproc usage ... not understanding
Date: Wed, 03 Aug 2011 13:11:29 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv: Gecko/20100228 Thunderbird/ Mnenhy/

I'm trying to make first use of a coproc and having difficulties.

Multiple versions I've tried (so exact details like how to do
redirection in statement 10, have been varied in many non-working ways!
But showing the last version:


  1. #!/bin/bash  -eux
  2. coproc parselast { sleep 1;grep -P '^[A-Z]+=[A-Z]+$' |
  3.                                                 sed 's/=/=$/'; }
  4. gcc -E -dM /usr/include/errno.h |
  5.     grep -P 'define\sE'|
  6.     sort -k3 -n|
  7.     sed 's/^#define //; s/ /=/ ' |
  8.     tee /proc/self/fd/${parselast[1]} |
  9.     grep -P '^[A-Z]+=\d+$'
 10.  0<&${parselast[0]} cat &  exec "${parselast[1]}>&-"


Comments: I'm using 'gcc' to get to all of the 'defines' in
errno.h, filtering only for those defines that are defining and
errno value, and turning the #defines into an assignment statement.
The problem is this (showing the first bit out output of my
filter & sort:

   #define EPERM 1
   #define ENOENT 2
   #define ESRCH 3


The first 3 defines -- I don't want to 'eval' until the ones with
real numbers have been done.  Thus I split the output @ 8 and try to send
a copy to the coproc, who would search for the non-numeric defines,
make them into xxx=$xxxx, so they would get the value they are defined
to.  But to do that, I need to have them done last.  Without that, I get:

#define EPERM 1
#define ENOENT 2
#define ESRCH 3

So first I output the numeric part of the list (which works and I see),
but then I try to read in the output from the coproc -- which has
supposedly received a copy of my input.
Instead, I read back nothing.  I either get errors about redirection,
errors about coprocs still hanging around, or just no output, depending
on what version I've used of line 10.

I send of 'cat' into background on 10, so I can proceed to closing
the fd connected to the coproc's input handle, so it will see 'end of
input', and flush it's output buffers.  Given the message lengths
involved, I'd hoped it wouldn't need any special 'waiting around'
period in the coproc, since all the output should have been written,
but who knows, that assumption could be the problem -- but I'd at
least think I'd get 1 line of input (i.e. if output was done
line by line and the coproc exited after outputting only 1 line). I figure, having moved at least 1 line of coproc's output to stdin.

I've searched for coproc usage examples on the web, but there aren't
many, and the few I found, while working for their test case, didn't
fully replicate my setup, so it didn't work.


What am I doing wrong?



(GNU bash, version 4.1.10(1)-release (x86_64-suse-linux-gnu))

reply via email to

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