www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Run child process with null stdin/stdout

reply "David Nadlinger" <code klickverbot.at> writes:
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
Jun 18 2014
parent reply Justin Whear <justin economicmodeling.com> writes:
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.
Jun 18 2014
parent reply "David Nadlinger" <code klickverbot.at> writes:
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
Jun 18 2014
parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
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 std=
in
 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 wou=
ld =
 have liked to avoid platform-dependent code.

 Hm, I just checked the source, and there doesn't seem to be a better  =
 option indeed=E2=80=A6
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
Jun 19 2014