Hi David,

ok,  it seems very minimal if implemented like a writeable file:

     public static abstract class Redirect {
+        private static final File nullFile = AccessController.doPrivileged(
+                (PrivilegedAction<File>) () -> {
+                    return new File((System.getProperty("os.name")
+                            .startsWith("Windows") ? "NUL" : "/dev/null"));
+                }
+        );
+

...
+
+        /**
+         * Indicates that subprocess output will be discarded by writting
+         * to the <em>null</em> device.
+         *
+         * <p>It will always be true that
+         * <pre> {@code
+         * Redirect.DISCARD.file() the null filename appropriate for the OS
+         * Redirect.DISCARD.type() == Redirect.Type.WRITE &&
+         * Redirect.DISCARD.append() == false
+         * }</pre>
+         */
+        public static final Redirect DISCARD = new Redirect() {
+                public Type type() { return Type.WRITE; }
+                public String toString() { return type().toString(); }
+                public File file() { return nullFile; }
+                boolean append() { return false; }
+        };
+

You're welcome to drive the addition yourself.
In some cases, writing the tests can take more time than the feature.

Roger


On 7/27/2015 2:09 PM, David M. Lloyd wrote:
Roger & co.:

Since you're already on the topic of manipulating pipes, I thought I'd mention one very small yet very useful potential enhancement.

It would be very handy to be able to specify a NULL/bit-bucket source/destination for pipes. For the target process' input, the user can generally (I believe) just close the stream, but for output, there isn't really a good option. While this is possible to achieve by redirecting to /dev/null on UNIX-likes and NUL (iirc) on Windows, having to do platform detection to decide where this device is seems overly cumbersome.

Having a ProcessBuilder.Redirect#DISCARD or similar would be quite useful, and should be fairly straightforward I think.

Reply via email to