> On Feb 7, 2012, at 4:19 PM, Helmut Eller wrote:
>> * Per Bothner [2012-02-07 19:18] writes:
>>>>> (run in: (run "command1") "command2")
>>>> How's this implemented in Java? Is there even a JDK API to create
>>> The default (and initial) implementation would just use a helper
>>> It reads from the output stream of command1, and writes to the input
>>> stream of command2. Do you know of any problems (like risk of
>>> doing it this way?
>> No; it just sounds inefficient.
> It wouldn't be that hard to call through to pipe(2), especially with
> The tricky part is that then we'd have to have a way to get the file
> descriptor ints used by pipe() to be used by the
> of the child Process with calls to read(2) and write(2). That seems like
> it would imply a custom InputStream subclass, which would imply a custom
> Process subclass to return our special InputStream, which would imply
> using the Process subtype returned by Runtime.exec() or
> So, we'd probably have to use JNI to call fork/exec or pthread_spawn().
> Doesn't really seem worth it.
A problem is that fork only forks the thread that called it. For a JVM
that often means that the GC doesn't work properly in the child process.
It's probably easier/necessary to write such things in C/C++ directly
which doesn't depend on other threads.