For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).
Pipe
struct Pipe
Create a pipe for interprocess communication.
Example usage:
from os.process import Pipe
def main() raises:
var pipe = Pipe()
pipe.write_bytes("TEST".as_bytes())
Fields
- fd_in (
Optional[FileDescriptor]): File descriptor for pipe input. - fd_out (
Optional[FileDescriptor]): File descriptor for pipe output.
Implemented traits
AnyType,
ImplicitlyDestructible
Methods
__init__
__init__(out self, in_close_on_exec: Bool = True, out_close_on_exec: Bool = True)
Initializes a new Pipe.
Args:
- in_close_on_exec (
Bool): Close the read side of pipe if anexecsyscall is issued in the process. - out_close_on_exec (
Bool): Close the write side of pipe if anexecsyscall is issued in the process.
Raises:
Error: If the pipe could not be created or configured.
__del__
__del__(deinit self)
Ensures pipes input and output file descriptors are closed, when the object is destroyed.
set_input_only
set_input_only(mut self)
Close the output descriptor/ channel for this side of the pipe.
set_output_only
set_output_only(mut self)
Close the input descriptor/ channel for this side of the pipe.
write_bytes
write_bytes(mut self, bytes: Span[UInt8])
Writes a span of bytes to the pipe.
Args:
- bytes (
Span[UInt8]): The byte span to write to this pipe.
Raises:
Error: If called on a read-only pipe.
read_bytes
read_bytes(mut self, buffer: Span[UInt8]) -> UInt
Read a number of bytes from this pipe.
Args:
- buffer (
Span[UInt8]): Span[Byte] of length n where to store read bytes. n = number of bytes to read.
Returns:
UInt: Actual number of bytes read.
Raises:
Error: If the pipe is in write-only mode.