mirror of
https://github.com/oven-sh/bun
synced 2026-02-18 06:41:50 +00:00
Actually buffer subproc output
This commit is contained in:
@@ -3625,7 +3625,8 @@ pub const Interpreter = struct {
|
||||
log("cmd ({x}) close buffered stdout", .{@intFromPtr(this)});
|
||||
if (this.io.stdout == .std and this.io.stdout.std.captured != null and !this.node.redirect.stdout) {
|
||||
var buf = this.io.stdout.std.captured.?;
|
||||
buf.append(bun.default_allocator, this.exec.subproc.child.stdout.pipe.slice()) catch bun.outOfMemory();
|
||||
const the_slice = this.exec.subproc.child.stdout.pipe.slice();
|
||||
buf.append(bun.default_allocator, the_slice) catch bun.outOfMemory();
|
||||
}
|
||||
this.exec.subproc.buffered_closed.close(this, .{ .stdout = &this.exec.subproc.child.stdout });
|
||||
this.exec.subproc.child.closeIO(.stdout);
|
||||
|
||||
@@ -683,6 +683,7 @@ pub const PipeReader = struct {
|
||||
stdio_result: StdioResult,
|
||||
captured_writer: CapturedWriter = .{},
|
||||
out_type: bun.shell.subproc.ShellSubprocess.OutKind,
|
||||
buffered: bun.ByteList = .{},
|
||||
ref_count: u32 = 1,
|
||||
|
||||
pub usingnamespace bun.NewRefCounted(PipeReader, deinit);
|
||||
@@ -819,6 +820,7 @@ pub const PipeReader = struct {
|
||||
|
||||
pub fn onReadChunk(ptr: *anyopaque, chunk: []const u8, has_more: bun.io.ReadState) bool {
|
||||
var this: *PipeReader = @ptrCast(@alignCast(ptr));
|
||||
this.buffered.append(bun.default_allocator, chunk) catch bun.outOfMemory();
|
||||
log("PipeReader onReadChunk({x}, ...)", .{@intFromPtr(this)});
|
||||
if (this.captured_writer.writer.getPoll() == null) {
|
||||
this.captured_writer.writer.handle = .{ .poll = Async.FilePoll.init(this.eventLoop(), if (this.out_type == .stdout) bun.STDOUT_FD else bun.STDERR_FD, .{}, @TypeOf(this.captured_writer.writer), &this.captured_writer.writer) };
|
||||
@@ -881,7 +883,7 @@ pub const PipeReader = struct {
|
||||
}
|
||||
|
||||
pub fn slice(this: *PipeReader) []const u8 {
|
||||
return this.reader.buffer().items[0..];
|
||||
return this.buffered.slice();
|
||||
}
|
||||
|
||||
pub fn toOwnedSlice(this: *PipeReader) []u8 {
|
||||
@@ -980,6 +982,8 @@ pub const PipeReader = struct {
|
||||
bun.default_allocator.free(this.state.done);
|
||||
}
|
||||
|
||||
this.buffered.deinitWithAllocator(bun.default_allocator);
|
||||
|
||||
this.reader.deinit();
|
||||
this.destroy();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user