Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drain stdout pipe while command is running #614

Merged
merged 5 commits into from
Oct 14, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
also drain stderr
  • Loading branch information
jflan-dd committed Jul 12, 2024
commit fbd6bded66a61838c1114bb3d2f588cc82c0128a
4 changes: 3 additions & 1 deletion Sources/DangerShellExecutor/ShellExecutor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ public struct ShellExecutor: ShellExecuting {
let stdoutData = stdout.fileHandleForReading.readDataToEndOfFile()
let stdoutString = String(data: stdoutData, encoding: .utf8)!

// Read from STDERR to ensure the `Pipe` does not fill up
let stderrData = stderr.fileHandleForReading.readDataToEndOfFile()

task.waitUntilExit()

// 0 is no problems in unix land
Expand All @@ -98,7 +101,6 @@ public struct ShellExecutor: ShellExecuting {
}

// OK, so it failed, raise a new error with all the useful metadata
let stderrData = stderr.fileHandleForReading.readDataToEndOfFile()
let stderrString = String(data: stderrData, encoding: .utf8)!

throw SpawnError.commandFailed(command: command,
Expand Down
Loading