ceylon-sdk icon indicating copy to clipboard operation
ceylon-sdk copied to clipboard

Make ceylon.process support writing stdin from string

Open sadmac7000 opened this issue 10 years ago • 3 comments

Feeding standard input from a string to a ceylon.process process is currently impossible without much pain. I think this should be improved.

sadmac7000 avatar Jun 24 '15 10:06 sadmac7000

Well we're kind of at the mercy of the underlying JDK APIs here, which I find pretty inconvenient. Do you have a specific suggestion?

gavinking avatar Jun 24 '15 11:06 gavinking

I asked @sadmac7000 to open this. In my opinion it is reasonable to expect ceylon.process to support this if it can be implemented reasonably using the Java APIs. Maybe that would not be possible (it's a while since I looked at them in detail), but we should try.

tombentley avatar Jun 24 '15 11:06 tombentley

Having reviewed the API that Java gives us it seems like we are pretty limited.

@tombentley said:

You can either handle the OutputStream yourself (dealing with the fact that write() might well block), or you can inherit or pass a File. So to cope with the blocking you either have to use threads, or I suppose in the case that you're going to wait for the process to exit you could use the current thread somehow But in the case where you want to read and write to all three standard streams.. well then you might get stuck blocked on a read() from stdout, for example while the process is waiting for something on stdin. I suppose InputStream does have available(), but reading the javadoc doesn't really inspire confidence, and it's not going to eliminate the possibility of deadlock anyway. So you're left with threads to do the IO in the background. Yuck.

@sadmac7000 said:

why not use threads then? It's good enough for the linux aio API

I think we really need to figure out what the Ceylon API would look like. If we're happy to use threads and we're just concerned with input then it seems like we could add a ByteInput case to Input. It would be nice to add a StringInput too, but then we'd need to worry about encodings, which would require ceylon.io as a dependency.

But in general the input could depend on the output, and we don't want to expose low-level details like threads.

tombentley avatar Jun 25 '15 09:06 tombentley