ProcessBuilder support for pipelines
On most operating systems, creating pipelines of processes is simple and direct. That same function is missing from the Java Process support and can be provided by java.lang.ProcessBuilder by enabling the pipes created for stdout to be used for standard input when the processes are created. Comments and feedback are appreciated on the prototype API and implementation. Javadoc: java.lang.ProcessBuilder.startPipe: http://cr.openjdk.java.net/~rriggs/pipedoc/java/lang/ProcessBuilder.html#sta... webrev prototype: http://cr.openjdk.java.net/~rriggs//webrev-pipeline-8132394 Thanks, Roger
In the past, when I contemplated doing this, I generally thought that there wasn't enough value in such a feature for the effort, given that one can start a subprocess shell that supports pipelines. Does this feature pull its weight? You don't need this to re-implement emacs in java, which has always been my litmus test. The missing feature is pty support, that y'all are less likely to add... On Mon, Jul 27, 2015 at 7:48 AM, Roger Riggs <Roger.Riggs@oracle.com> wrote:
On most operating systems, creating pipelines of processes is simple and direct. That same function is missing from the Java Process support and can be provided by java.lang.ProcessBuilder by enabling the pipes created for stdout to be used for standard input when the processes are created. Comments and feedback are appreciated on the prototype API and implementation.
Javadoc: java.lang.ProcessBuilder.startPipe:
http://cr.openjdk.java.net/~rriggs/pipedoc/java/lang/ProcessBuilder.html#sta...
webrev prototype: http://cr.openjdk.java.net/~rriggs//webrev-pipeline-8132394
Thanks, Roger
On 07/28/2015 02:48 AM, Martin Buchholz wrote:
In the past, when I contemplated doing this, I generally thought that there wasn't enough value in such a feature for the effort, given that one can start a subprocess shell that supports pipelines. Does this feature pull its weight?
Feeding program arguments to command spawned by a shell is difficult. There is also no good way to obtain the exit status of the first command in the pipe. The last command in the pipe determines the shell exit status, and earlier commands are ignored. -- Florian Weimer / Red Hat Product Security
On Tue, Jul 28, 2015 at 2:36 AM, Florian Weimer <fweimer@redhat.com> wrote:
On 07/28/2015 02:48 AM, Martin Buchholz wrote:
In the past, when I contemplated doing this, I generally thought that there wasn't enough value in such a feature for the effort, given that one can start a subprocess shell that supports pipelines. Does this feature pull its weight?
Feeding program arguments to command spawned by a shell is difficult.
You know what would actually be really useful? String shellQuote(List<String> args) but that is Unix-shell specific, so historically difficult to convince JDK maintainers to add. But culture has changed towards the pragmatic... I've already written such a thing, but not in Java. There is also no good way to obtain the exit status of the first command
in the pipe. The last command in the pipe determines the shell exit status, and earlier commands are ignored.
Well, bash does have the "pipefail" feature.
Hi Martin, Doing the plumbing for this is pretty minimal as you've noticed from the webrev. No native code is modified and it extends the existing redirect logic. I think this is pretty useful and cheap and will work across platforms. I use emacs every day too but somehow it seems dated. Roger On 7/27/2015 8:48 PM, Martin Buchholz wrote:
In the past, when I contemplated doing this, I generally thought that there wasn't enough value in such a feature for the effort, given that one can start a subprocess shell that supports pipelines. Does this feature pull its weight?
You don't need this to re-implement emacs in java, which has always been my litmus test. The missing feature is pty support, that y'all are less likely to add...
On Mon, Jul 27, 2015 at 7:48 AM, Roger Riggs <Roger.Riggs@oracle.com <mailto:Roger.Riggs@oracle.com>> wrote:
On most operating systems, creating pipelines of processes is simple and direct. That same function is missing from the Java Process support and can be provided by java.lang.ProcessBuilder by enabling the pipes created for stdout to be used for standard input when the processes are created. Comments and feedback are appreciated on the prototype API and implementation.
Javadoc: java.lang.ProcessBuilder.startPipe: http://cr.openjdk.java.net/~rriggs/pipedoc/java/lang/ProcessBuilder.html#sta... <http://cr.openjdk.java.net/%7Erriggs/pipedoc/java/lang/ProcessBuilder.html#startPipe-java.lang.ProcessBuilder...->
webrev prototype: http://cr.openjdk.java.net/~rriggs//webrev-pipeline-8132394 <http://cr.openjdk.java.net/%7Erriggs//webrev-pipeline-8132394>
Thanks, Roger
I find this kinda cute. Seems like a reasonable addition to me. -Chris. On 27 Jul 2015, at 15:48, Roger Riggs <Roger.Riggs@oracle.com> wrote:
On most operating systems, creating pipelines of processes is simple and direct. That same function is missing from the Java Process support and can be provided by java.lang.ProcessBuilder by enabling the pipes created for stdout to be used for standard input when the processes are created. Comments and feedback are appreciated on the prototype API and implementation.
Javadoc: java.lang.ProcessBuilder.startPipe: http://cr.openjdk.java.net/~rriggs/pipedoc/java/lang/ProcessBuilder.html#sta...
webrev prototype: http://cr.openjdk.java.net/~rriggs//webrev-pipeline-8132394
Thanks, Roger
Seems like a useful addition to me. Stephen On 28 July 2015 at 09:28, Chris Hegarty <chris.hegarty@oracle.com> wrote:
I find this kinda cute. Seems like a reasonable addition to me.
-Chris.
On 27 Jul 2015, at 15:48, Roger Riggs <Roger.Riggs@oracle.com> wrote:
On most operating systems, creating pipelines of processes is simple and direct. That same function is missing from the Java Process support and can be provided by java.lang.ProcessBuilder by enabling the pipes created for stdout to be used for standard input when the processes are created. Comments and feedback are appreciated on the prototype API and implementation.
Javadoc: java.lang.ProcessBuilder.startPipe: http://cr.openjdk.java.net/~rriggs/pipedoc/java/lang/ProcessBuilder.html#sta...
webrev prototype: http://cr.openjdk.java.net/~rriggs//webrev-pipeline-8132394
Thanks, Roger
Curmudgeon Martin supports this change! I'm a little surprised we can implement it without native code. --- The below should probably be in its own paragraph. + * The {@link #startPipe startPipe} method can be invoked to create + * a pipeline of new processes that send the output of each process + * directly to the next process. Each process has the attributes of + * its respective ProcessBuilder. --- I continue to be opposed to throwing UOE. But it seems I've lost that nano-argument. + * @throws UnsupportedOperationException + * If the operating system does not support the creation of processes. --- These statements are technically incorrect. + * The standard output of all processes except the first process + * are <i>null output streams</i> + * The standard input of all processes except the last process + * are <i>null input streams</i>. What you mean is that getOutputStream etc return null streams, but that's not what you say. --- Should this mention standard error? + * @throws IllegalArgumentException any of the redirects except the + * standard input of the first builder and the standard output of + * the last builder are not {@link Redirect#PIPE}.
participants (5)
-
Chris Hegarty
-
Florian Weimer
-
Martin Buchholz
-
Roger Riggs
-
Stephen Colebourne