[Top][All Lists]

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

Re: redirecting a file descriptor to an array variable? Possible? How? R

From: Linda Walsh
Subject: Re: redirecting a file descriptor to an array variable? Possible? How? RFE?
Date: Wed, 18 Nov 2015 10:46:57 -0800
User-agent: Thunderbird

konsolebox wrote:
On Fri, Nov 13, 2015 at 8:45 AM, Linda Walsh <address@hidden> wrote:
I'd like to be able to record stdout and stderr
without using any temp files into bash array files, AND
record the status of the command executed.

You can use coproc processes that would act as buffers.
Obvious Note: Avoid it if you're conservative about some undocumented
areas that would look too hacky to you.
        More often people think my code looks hacky because
I haven't used alot of Integrated GUI+Devel platforms,
        Re... using coprocs.... hadn't even though of those
(probably since I haven't had good luck with them working the way
I expected).

        Maybe I'll work w/that, or maybe will try a refactor
of my current code to combine the output streams in 1 sub and that
might make my return of the 'exit code'($?) easier.

        # TODO: Not sure how a proper coproc cleanup is done.  Closing
FDs does funny things.  Perhaps it's automatic, but not sure how
disown affects it.  We could examine the source code but not sure if
that would be reliable enough for all versions of bash including the
upcoming ones.
        One thing I found useful is where you have
2 procs talking over a pipe, and the reader needs time to finish the pipe
read before parent closes it.  So instead of just closing a pipe, I
open a pair of pipes w/1 going in reverse direction. Then parent can send
various control commands to child while the child is generating output
so the child won't end prematurely.

        As mentioned, was close but wasn't feeling right about
it.  But some things that simplify my life.  I'm running
commands that talk to the terminal.  None of them _should_ be putting
out NULs... and going off on red-herring rat-holes isn't the best
way to get something that works.
        One thing that seems to be another problem.  Greg called
my attention to another printf format bug:

             %q     causes  printf  to output the corresponding argument in a
                    format that can be reused as shell input.

        Which it doesn't when nuls are involved.

reply via email to

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