Skip to content

Commit

Permalink
Update process.Pipe to return List[Byte] on read
Browse files Browse the repository at this point in the history
Conform `read_bytes` on Pipe utility object to updated file descriptor
`read_bytes` api

Signed-off-by: Hristo I. Gueorguiev <53634432+izo0x90@users.noreply.github.com>
  • Loading branch information
izo0x90 committed Feb 25, 2025
1 parent ab13502 commit 0ce641a
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions stdlib/src/os/process.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ Example:
from os import Process
```
"""
from collections import Optional
from collections.string import StringSlice
from collections import List, Optional

from sys import (
os_is_linux,
Expand Down Expand Up @@ -137,15 +136,15 @@ struct Pipe:
raise Error("Can not write from read only side of pipe")

@always_inline
fn read_bytes(mut self, size: Int) raises -> Span[Byte, MutableAnyOrigin]:
fn read_bytes(mut self, size: Int) raises -> List[Byte]:
"""
Read a span of bytes from this pipe.
Read a number of bytes from this pipe.
Args:
size: The number of bytes to read from this pipe.
Returns:
Span of bytes with len=size read from this pipe.
List of bytes with len=size read from this pipe.
"""
if self.fd_in:
return self.fd_in.value().read_bytes(size)
Expand Down Expand Up @@ -265,7 +264,7 @@ struct Process:
raise Error("Unable to fork parent")

pipe.set_input_only()
var err: Optional[Span[Byte, MutableAnyOrigin]]
var err: Optional[List[Byte]]
try:
err = pipe.read_bytes(exec_err_code.byte_length())
except e:
Expand All @@ -274,7 +273,7 @@ struct Process:
if (
err
and len(err.value()) > 0
and StringSlice(unsafe_from_utf8=err.value()) == exec_err_code
and err.value().__str__() == exec_err_code
):
raise Error("Failed to execute " + path)

Expand Down

0 comments on commit 0ce641a

Please sign in to comment.