Skip to content

Commit 3791236

Browse files
committed
Make eofTimeout configurable
1 parent f851012 commit 3791236

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

Sources/ShellOut.swift

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ import Logging
3737
logger: Logger? = nil,
3838
outputHandle: FileHandle? = nil,
3939
errorHandle: FileHandle? = nil,
40-
environment: [String : String]? = nil
40+
environment: [String : String]? = nil,
41+
eofTimeout: DispatchTimeInterval = .milliseconds(10)
4142
) throws -> (stdout: String, stderr: String) {
4243
let command = "cd \(path.escapingSpaces) && \(command) \(arguments.map(\.string).joined(separator: " "))"
4344

@@ -46,7 +47,8 @@ import Logging
4647
logger: logger,
4748
outputHandle: outputHandle,
4849
errorHandle: errorHandle,
49-
environment: environment
50+
environment: environment,
51+
eofTimeout: eofTimeout
5052
)
5153
}
5254

@@ -94,7 +96,8 @@ import Logging
9496
logger: Logger? = nil,
9597
outputHandle: FileHandle? = nil,
9698
errorHandle: FileHandle? = nil,
97-
environment: [String : String]? = nil
99+
environment: [String : String]? = nil,
100+
eofTimeout: DispatchTimeInterval = .milliseconds(10)
98101
) throws -> (stdout: String, stderr: String) {
99102
try shellOut(
100103
to: command.command,
@@ -104,7 +107,8 @@ import Logging
104107
logger: logger,
105108
outputHandle: outputHandle,
106109
errorHandle: errorHandle,
107-
environment: environment
110+
environment: environment,
111+
eofTimeout: eofTimeout
108112
)
109113
}
110114

@@ -434,7 +438,14 @@ extension ShellOutCommand {
434438
// MARK: - Private
435439

436440
private extension Process {
437-
@discardableResult func launchBash(with command: String, logger: Logger? = nil, outputHandle: FileHandle? = nil, errorHandle: FileHandle? = nil, environment: [String : String]? = nil) throws -> (stdout: String, stderr: String) {
441+
@discardableResult func launchBash(
442+
with command: String,
443+
logger: Logger? = nil,
444+
outputHandle: FileHandle? = nil,
445+
errorHandle: FileHandle? = nil,
446+
environment: [String : String]? = nil,
447+
eofTimeout: DispatchTimeInterval = .milliseconds(10)
448+
) throws -> (stdout: String, stderr: String) {
438449
self.executableURL = URL(fileURLWithPath: "/bin/bash")
439450
self.arguments = ["-c", command]
440451

@@ -487,7 +498,7 @@ private extension Process {
487498
try self.run()
488499
self.waitUntilExit()
489500

490-
if outputGroup.wait(timeout: .now() + .milliseconds(100)) == .timedOut {
501+
if outputGroup.wait(timeout: .now() + eofTimeout) == .timedOut {
491502
logger?.warning("ShellOut.launchBash: Timed out waiting for EOF! (command: \(command))")
492503
}
493504

0 commit comments

Comments
 (0)