bug-bash
[Top][All Lists]
Advanced

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

redirecting a file descriptor to an array variable? Possible? How? RFE?


From: Linda Walsh
Subject: redirecting a file descriptor to an array variable? Possible? How? RFE?
Date: Thu, 12 Nov 2015 16:45:49 -0800
User-agent: Thunderbird



I'm coming up with a null-record in my brain when I think
about this:  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.

Something along the lines of

Array stderr=() stdout=()
runprog () {
   "RUN" cmd 2>@stderr   1>${stdout[@]}; status=$?
             ##^-pseudo or ^-syntax
   return $status
}


----
If there is too much output to fit into an array,
the same thing would happen as if one did something like
readarray ARRAY < <(while :;do echo "lots of lines";done)
(i.e. it would eventually overflow something).

---
But for the most part, I'm thinking smaller output commands
where one just wants to catch fd 1 & 2 and status and have
those returned in parameterized arrays and a return value of
the cmd or function.

I  cobbled together something that returned stderr/stdout, and it
worked for the simple cases I tried, but it seemed awfully overblown
and inflated for what I was trying to do.
Then tried to pass back status, and the whole thing fell apart -- at
which point, I was thinking -- there's gotta be an easier way that I'm
missing -- I seem to be making this a whole heck of a lot more complicated
than it needs to be.

One thing to remember -- I don't want to use data structures external
to bash (like external files), as I can't be sure where I'd be allowed
to write them without going through some undesirable kludges...

Thanks!
-l






reply via email to

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