Fork me on GitHub
#planck
<
2016-06-22
>
johanatan00:06:00

[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]

mfikes00:06:28

I’m wondering what clojure.java.shell ends up causing Java to do at the OS level.

mfikes00:06:16

@johanatan: I’ll read up on the popen / fork / pipe business. I’ve never tried doing things things at this level before 🙂

johanatan00:06:29

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).

mfikes00:06:05

Sounds like temp files would work, but obviously not a desired outcome if it can be avoided. (I don’t understand the APIs yet.)

mfikes00:06:04

If nothing else, perhaps a temp-file based approach could be implemented and then we could revisit it as we learn more.

johanatan00:06:25

Well, I think the next best option would be the one I mentioned earlier

johanatan00:06:29

Inspired by kangear's post

johanatan00:06:43

but it will be probably 100-120 lines of C instead of like 15 lines 🙂

johanatan00:06:22

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

johanatan00:06:02

[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]

johanatan00:06:24

[but I don't know if adding a dependency like that would be desirable or not]

mfikes01:06:56

@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

mfikes01:06:15

@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.

johanatan05:06:41

yes, that's the "solution inspired by kangear" I referred to. 🙂 no, it's not too much work for me

johanatan05:06:02

oops, sorry. that's a different solution involving a manual fork() and execv() rather than popen(). i remember running across that one too

johanatan05:06:18

i just wanted to make sure we agreed on the approach before I coded it. thx!

mfikes16:06:15

@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.