Skip to content

Commit 7d30720

Browse files
authored
CLI: Fix -it not being able to pipe stdout (apple#951)
Fixes apple#949 Typically if one fd is a tty, it's common for all 3 of stdio to be the same, but that is not always the case. In our case we were using our Terminal type from Containerization to comb through err/out/in and give us a type backed by one of the 3 if -t was supplied. It happens that stderr is the first we check, so our Terminal() is backed by fd 2. This change modifies things so that we always initialize our Terminal if asked for with fd 0, and out/err are backed by their corresponding correct fd number. ## Type of Change - [x] Bug fix - [ ] New feature - [ ] Breaking change - [ ] Documentation update ## Testing - [x] Tested locally - [ ] Added/updated tests - [ ] Added/updated docs
1 parent a2901e0 commit 7d30720

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

Sources/ContainerClient/ProcessIO.swift

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public struct ProcessIO: Sendable {
4848
if !tty || !interactive {
4949
return nil
5050
}
51-
let current = try Terminal.current
51+
let current = try Terminal(descriptor: STDIN_FILENO)
5252
try current.setraw()
5353
return current
5454
}()
@@ -94,13 +94,9 @@ public struct ProcessIO: Sendable {
9494
let (stream, cc) = AsyncStream<Void>.makeStream()
9595
if let stdout {
9696
configuredStreams += 1
97-
let pout: FileHandle = {
98-
if let current {
99-
return current.handle
100-
}
101-
return .standardOutput
102-
}()
10397

98+
stdio[1] = stdout.fileHandleForWriting
99+
let pout = FileHandle.standardOutput
104100
let rout = stdout.fileHandleForReading
105101
rout.readabilityHandler = { handle in
106102
let data = handle.availableData
@@ -111,7 +107,6 @@ public struct ProcessIO: Sendable {
111107
}
112108
try! pout.write(contentsOf: data)
113109
}
114-
stdio[1] = stdout.fileHandleForWriting
115110
}
116111

117112
let stderr: Pipe? = {

0 commit comments

Comments
 (0)