swift scripts run in the background with swift launched via swiftly will make the current shell exit
## Steps to Reproduce
- Create a file `yolo.swift` that contains the following content:
```swift
#!/usr/bin/env swift
print("hello")
```
- Make it executable
- Run it like so with `swiftly` properly installed and in the `PATH`:
```bash
./yolo.swift &
```
## Expected Behavior
The script should run in the background, output `hello` and then exit, and the shell should stay alive.
## Actual Behavior
The script launches in the background, but zsh errors out reading the TTY and exits:
```text
prompt) ./toto.swift &
[1] 64386
prompt)
zsh: error on TTY read: Input/output error
zsh: warning: 1 jobs SIGHUPed
[1] + hangup ./toto.swift
prompt)
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.
[Process completed]
```
## Environment
- macOS 26.2 (25C56)
- Terminal 2.15 (466)
- zsh 5.9 (arm64-apple-darwin25.0)
- swiftly 1.1.1
- swift from Xcode:
```text
swift-driver version: 1.127.14.1 Apple Swift version 6.2 (swiftlang-6.2.3.3.20 clang-1700.6.3.2)
Target: arm64-apple-macosx26.0
```
## My Analysis
I’m not 100% sure that’s the problem, but I’m pretty sure the issue actually comes from [swift-subprocess](<https://github.com/swiftlang/swift-subprocess>). I actually had this exact same issue with [my own “subprocess” implementation](<https://github.com/xcode-actions/swift-process-invocation>) (I really should write a Readme…).
The [fix](<https://github.com/xcode-actions/swift-process-invocation/commit/382dc979de2b080920d8fdcc19705265ccf8eeb5#diff-b73f49f2c203aea220b84ffcec7bcc4e542a50838ad38524dc10a483b4957405R467-R471>) consisted in _not_ setting the current process group ID of the input file descriptor if the process was in the background (which I determined by checking whether the current process group ID of the file descriptor is my own process group ID).
0 条评论