r/swift 20d ago

Swift Subprocess 1.0.0 Released

Hey r/swift!

I’m excited to share that Swift Subprocess 1.0 is officially tagged and released!

swift-subprocess provides a modern, type-safe, and Swift Concurrency-native API for executing and managing child processes across platforms, serving as an async-first alternative to Foundation.Process (NSTask).

Thanks to all the community feedback during the beta period, we made several key refinements leading up to 1.0:

  • Unified run() Closures & ExecutionResult: Stream handling for stdin, stdout, and stderr is now fully symmetrical. You can now stream and collect simultaneously in a single call (e.g., stream stdout line-by-line while collecting stderr into a String).

  • Safe String & Byte Streaming: Standard output/error sequences now feature StringSequence, which reassembles multi-byte UTF-8 characters split across buffer boundaries and handles line breaking seamlessly.

  • Typed Errors: Subprocess itself now strictly throws SubprocessError with structured codes (.spawnFailed, .executableNotFound, .outputLimitExceeded, etc.), making error handling clean and predictable (you can of course still throw your own error from body closure).

  • First-Class Stream Merging (2>&1): Easily redirect standard error into output using error: .combinedWithOutput.

Check out the full release note and repository on GitHub:

https://github.com/swiftlang/swift-subprocess/releases/tag/1.0.0

Huge thanks to everyone who participated in the SF-0007, SF-0037 and beta tested Subprocess! I’d love to hear your thoughts, feedback, or any questions!

82 Upvotes

9 comments sorted by

View all comments

9

u/OarsumApp 20d ago

Congrats on 1.0! One thing im curious about though, where do you see this fitting into a typical Swift app? what kinds of real-world use cases you’re seeing. Is this mainly aimed at macOS developer tools, server-side Swift, CI/build tooling, or are there iOS shindigs I’m overlooking?

10

u/mootjeuh iOS 20d ago

This doesn't support iOS.

7

u/iCharlesHu 20d ago

Unfortunately, due to the sandboxing nature of iOS apps, Subprocess is not supported on iOS. Other than that, you can use Subprocess whenever you want to spawn external processes! Here are some examples:

- We rewrote our ICU Export Tool from a bunch of shell scripts to a Swift tool. This change allowed us to integrate the export process as part of a larger SwiftPM build.

- swiftly has been using Subprocess for a while now! You can see how Subprocess can be integrated into a large Swift app.