# Swift and exit codes?

**URL:** <https://forums.swift.org/t/swift-and-exit-codes/71209>\
**Category:** Using Swift\
**Created:** [April 12, 2024, 12:57am UTC](https://forums.swift.org/t/swift-and-exit-codes/71209 "2024-04-12T00:57:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![taylorswift](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/taylorswift/32/43413_2.png) [@taylorswift](https://forums.swift.org/u/taylorswift)\
**Post date:** [April 12, 2024, 12:57am UTC](https://forums.swift.org/t/swift-and-exit-codes/71209/1 "2024-04-12T00:57:37Z")

</div>

my goal here is to spawn a child process that has several different known failure modes, and obtain the failure type (if known) from the parent process. but exit codes are [a bit of a minefield](https://forums.swift.org/t/exit-codes-from-main/61698), and this needs to work consistently on both linux and macOS.

how should a child process communicate a failure mode to its parent?

---

<div class="post-metadata">

**Author:** ![wes1](https://avatars.discourse-cdn.com/v4/letter/w/848f3c/32.png) [@wes1](https://forums.swift.org/u/wes1)\
**Post date:** [April 12, 2024, 8:15pm UTC](https://forums.swift.org/t/swift-and-exit-codes/71209/3 "2024-04-12T20:15:52Z")

</div>

> [@taylorswift](#):
>
> my goal here is to spawn a child process that has several different known failure modes, and obtain the failure type (if known) from the parent process

FWIW, Shwift AFAICT settled into a stand-off where it boxes the error code or signal for you.

See e.g., the error boxing  
[https://github.com/GeorgeLyon/Shwift/blob/d7be04898d094ddce6140cc6a2e9a83fc994b66d/Sources/Script/Script.swift#L166](https://github.com/GeorgeLyon/Shwift/blob/d7be04898d094ddce6140cc6a2e9a83fc994b66d/Sources/Script/Script.swift#L166)

and the underlying enum

[https://github.com/GeorgeLyon/Shwift/blob/d7be04898d094ddce6140cc6a2e9a83fc994b66d/Sources/Shwift/Process.swift#L316](https://github.com/GeorgeLyon/Shwift/blob/d7be04898d094ddce6140cc6a2e9a83fc994b66d/Sources/Shwift/Process.swift#L316)

---

<div class="post-metadata">

**Author:** ![taylorswift](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/taylorswift/32/43413_2.png) [@taylorswift](https://forums.swift.org/u/taylorswift)\
**Post date:** [April 12, 2024, 10:33pm UTC](https://forums.swift.org/t/swift-and-exit-codes/71209/4 "2024-04-12T22:33:46Z")

</div>

i may be misreading the code, but as far as i can understand, it is just boxing the error code it observes from the child process’s exit; it doesn’t have any capability of namespacing application-defined exit codes. the application running in the child process would need to choose an error encoding that does not overlap with anything else, and that encoding would need to be portable across two platforms.

an alternative that would not suffer from this problem might be as simple as “write the application’s exit code to a text file that contains a single integer in a location specified by the caller”. but that seemed a little silly.
