View source code
Display the source code in std/process.d from which this
page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a
Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
std.process.Pipe/pipe
- multiple declarations
Function pipe
Creates a unidirectional pipe.
Data is written to one end of the pipe and read from the other.
auto p = pipe();
p .writeEnd .writeln("Hello World");
p .writeEnd .flush();
assert(p .readEnd .readln() .chomp() == "Hello World");
Pipes can, for example, be used for interprocess communication
by spawning a new process and passing one end of the pipe to
the child, while the parent uses the other end.
(See also pipeProcess
and pipeShell
for an easier
way of doing this.)
// Use cURL to download the dlang.org front page, pipe its
// output to grep to extract a list of links to ZIP files,
// and write the list to the file "D downloads.txt":
auto p = pipe();
auto outFile = File("D downloads.txt", "w");
auto cpid = spawnProcess(["curl", "http://dlang.org/download.html"],
stdin, p .writeEnd);
scope(exit) wait(cpid);
auto gpid = spawnProcess(["grep", "-o", `http://\S*\.zip`],
p .readEnd, outFile);
scope(exit) wait(gpid);
Returns
A Pipe
object that corresponds to the created pipe.
Throws
StdioException
on failure.
Struct Pipe
An interface to a pipe created by the pipe
function.
struct Pipe
;
Properties
Name | Type | Description |
---|---|---|
readEnd [get]
|
File | The read end of the pipe. |
writeEnd [get]
|
File | The write end of the pipe. |
Methods
Name | Description |
---|---|
close
()
|
Closes both ends of the pipe. |
Authors
Lars Tandle Kyllingstad, Steven Schveighoffer, Vladimir Panteleev
License
Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.