Open
Description
Describe the bug
I have a process I want to monitor that is long running. It has small and infrequent output that I need to get in as soon as it is available. I'm running this process with swift-subprocess and monitoring its output by using SequenceOutput
. In the custom execution closure, I only get the output either when the process exits or when the output size reaches readBufferSize
defined in AsyncBufferSequence
.
To Reproduce
Here is some sample code that demonstrates the problem:
let script = """
echo "[NOTICE] Important log line"
sleep 3600
"""
let catResult = try await Subprocess.run(
.path("/bin/bash"),
arguments: ["-c", script],
output: .sequence,
error: .discarded,
body: { (execution, _) in
for try await chunk in execution.standardOutput {
let string = chunk.withUnsafeBytes { String(decoding: $0, as: UTF8.self) }
if string.hasPrefix("[NOTICE]") {
// Do Something interesting
print(string)
}
}
return ""
}
)
Expected behavior
There should be a mechanism for getting the output as soon as it is available.
Environment (please complete the following information):
- macOS 15
- swift-driver version: 1.120.5 Apple Swift version 6.1 (swiftlang-6.1.0.110.21 clang-1700.0.13.3)
Additional context
I'll follow up with a PR that has the sketch for a proposed solution.