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

Fix for Process.run() fails with "Bad file descriptor" and Swift 5.8 #13

Open
wants to merge 1 commit into
base: async
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.5
// swift-tools-version:5.8
import PackageDescription

let package = Package(
Expand Down
5 changes: 3 additions & 2 deletions Sources/wkhtmltopdf/Document+Generate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ extension Document {
// Call wkhtmltopdf and retrieve the result data
let wk = Process()
let stdout = Pipe()
wk.launchPath = self.launchPath
wk.executableURL = URL(fileURLWithPath: self.launchPath)
wk.arguments = wkArgs
wk.arguments?.append("-") // output to stdout
wk.standardOutput = stdout
wk.launch()
try wk.run()

let pdf = stdout.fileHandleForReading.readDataToEndOfFile()
continuation.resume(returning: pdf)
try stdout.fileHandleForReading.close()
}.flatMapErrorThrowing { err in
continuation.resume(throwing: err)
return
Expand Down
2 changes: 1 addition & 1 deletion Tests/wkhtmltopdfTests/wkhtmltopdfTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class wkhtmltopdfTests: XCTestCase {
let threadPool = NIOThreadPool(numberOfThreads: 1)
threadPool.start()
let data = try await document.generatePDF(on: threadPool, eventLoop: eventLoop)
try threadPool.syncShutdownGracefully()
try await threadPool.shutdownGracefully()
// Cop-out test, just ensuring that the returned data is something
XCTAssert(data.count > 50)
// Visual test
Expand Down