Thread overview
Run child process with null stdin/stdout
Jun 18, 2014
David Nadlinger
Jun 18, 2014
Justin Whear
Jun 18, 2014
David Nadlinger
June 18, 2014
Hi all,

is there a platform independent way to do the equivalent of
"some_program < /dev/null > /dev/null" using std.process?

I neither want to capture/print the standard output of the child
process nor have anything available on its input.

Quite probably, I'm just missing something obvious…

Cheers,
David
June 18, 2014
On Wed, 18 Jun 2014 19:37:58 +0000, David Nadlinger wrote:

> Hi all,
> 
> is there a platform independent way to do the equivalent of "some_program < /dev/null > /dev/null" using std.process?
> 
> I neither want to capture/print the standard output of the child process nor have anything available on its input.
> 
> Quite probably, I'm just missing something obvious…
> 
> Cheers,
> David

`spawnProcess`: The optional arguments stdin, stdout and stderr may be used to assign arbitrary std.stdio.File objects as the standard input, output and error streams, respectively, of the child process. The former must be opened for reading, while the latter two must be opened for writing.

For POSIX, seems like you could pass `File("/dev/null", "r")` for stdin
and `File("/dev/null", "w")`.  On Windows I believe you can use `File
("nul")` for the same effect.
June 18, 2014
On Wednesday, 18 June 2014 at 20:00:43 UTC, Justin Whear wrote:
> For POSIX, seems like you could pass `File("/dev/null", "r")` for stdin
> and `File("/dev/null", "w")`.  On Windows I believe you can use `File
> ("nul")` for the same effect.

Implementing this myself is of course always an option, yes, but I would have liked to avoid platform-dependent code.

Hm, I just checked the source, and there doesn't seem to be a better option indeed…

Thanks,
David
June 19, 2014
On Wed, 18 Jun 2014 16:15:40 -0400, David Nadlinger <code@klickverbot.at> wrote:

> On Wednesday, 18 June 2014 at 20:00:43 UTC, Justin Whear wrote:
>> For POSIX, seems like you could pass `File("/dev/null", "r")` for stdin
>> and `File("/dev/null", "w")`.  On Windows I believe you can use `File
>> ("nul")` for the same effect.
>
> Implementing this myself is of course always an option, yes, but I would have liked to avoid platform-dependent code.
>
> Hm, I just checked the source, and there doesn't seem to be a better option indeed…
>

I think a mechanism to open a null stream in an OS independent way would be a good addition to std.stdio (or perhaps std.process?)

-Steve