[a similar method (redirecting both stdout and stderr to files instead of just stderr) is demonstrated here (in the OP): http://stackoverflow.com/questions/15155314/redirect-stdout-and-stderr-to-the-same-file-and-restore-it]
I’m wondering what clojure.java.shell
ends up causing Java to do at the OS level.
@johanatan: I’ll read up on the popen
/ fork
/ pipe
business. I’ve never tried doing things things at this level before 🙂
ok, my preferred approach would be the popen()
/`freopen()` combination mentioned above [as it's the least complex to implement] (assuming you're ok with temp files).
Sounds like temp files would work, but obviously not a desired outcome if it can be avoided. (I don’t understand the APIs yet.)
If nothing else, perhaps a temp-file based approach could be implemented and then we could revisit it as we learn more.
Well, I think the next best option would be the one I mentioned earlier
Inspired by kangear's post
but it will be probably 100-120 lines of C instead of like 15 lines 🙂
but i will wait for you to do some research and come to some conclusions as well. perhaps there is something my research has missed
[also, i was thinking it would be nice if there were some sort of 3rd party C library out there which handles this-- i'd imagine any sort of higher-level OS abstraction library would support this sort of thing]
[but I don't know if adding a dependency like that would be desirable or not]
@johanatan: I don’t know if this leads to the ability to construct a solution, but it can evidently be done with 3 pipes. In this gist, I gave errfd
a questionable variable name (because I was confused with what I was doing), but, it seems to work: https://gist.github.com/mfikes/52332f568be9da2dd72ee9376e5b9f34
@johanatan: It is true that it is a decent amount of code to cobble together. (And there is probably some sort of select
stuff that really needs to be done.) If it is more than you’d like to take on, certainly don’t feel obligated.
yes, that's the "solution inspired by kangear" I referred to. 🙂 no, it's not too much work for me
oops, sorry. that's a different solution involving a manual fork()
and execv()
rather than popen()
. i remember running across that one too
i just wanted to make sure we agreed on the approach before I coded it. thx!
@johanatan: Yeah… if a solution can be built using pipes rather than tmp files, I think it’s worth it, given that sh
is a pretty key feature, even if it involves a decent amount of code.
@mfikes: ok, cool