Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/pipe.toit
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class OpenPipe extends OpenPipe_:

class OpenPipe_ implements Stream:
resource_ := ?
state_ := ?
state_/monitor.ResourceState_? := ?
pid := null
child-process-name_ /string?
input_ /int := UNKNOWN-DIRECTION_
Expand Down Expand Up @@ -152,7 +152,9 @@ class OpenPipe_ implements Stream:

read_ -> ByteArray?:
while true:
if not state_: return null
state_.wait-for-state READ-EVENT_ | CLOSE-EVENT_
if not state_: return null
result := read-from-pipe_ resource_
if result != -1:
if result == null:
Expand Down
9 changes: 9 additions & 0 deletions tests/pipe3_exe.toit
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (C) 2025 Toit contributors.
// Use of this source code is governed by a Zero-Clause BSD license that can
// be found in the tests/TESTS_LICENSE file.

import host.pipe

main:
// Just wait for a message.
pipe.stdin.in.read
32 changes: 32 additions & 0 deletions tests/pipe3_test.toit
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (C) 2025 Toit contributors.
// Use of this source code is governed by a Zero-Clause BSD license that can
// be found in the tests/TESTS_LICENSE file.

import expect show *

import host.pipe
import system

main args:
toit-exe := args[0]

my-path := system.program-path
end := my-path.index-of --last "test.toit"
if end == -1: throw "UNEXPECTED"
input := "$my-path[..end]input.toit"

process := pipe.fork
--create-stdout
--create-stdin
toit-exe
[toit-exe, input]

to-process := process.stdin
from-process := process.stdout

from-process.close

expect-null from-process.in.read
to-process.out.write "done"

process.wait