[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Question: Capturing command output (on-screen keyword co
From: |
Eric Blake |
Subject: |
Re: [Help-bash] Question: Capturing command output (on-screen keyword colorizer/prettifier). |
Date: |
Thu, 6 Oct 2016 08:58:51 -0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 |
[please don't top-post on technical lists]
On 10/05/2016 07:35 PM, Matthew Giassa wrote:
> I managed to get 99% of the way there. I used dup()/pipe()/dup2() and
> hooked fork() to redirect stdout for bash and child processes to a
> dedicated per-process pipe.
That's part of your problem. It's better to redirect the children to a
pty than a pipe, because some children (a prime example is 'ls')
intentionally behave differently based on whether stdout is a pipe or a tty.
If you want more experience with ptys, the 'expect' program is a great
example. Opening a pty is the easiest way to pass ALL output from any
level of process descendant through your filtering code.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature