Cross-platform PTY (pseudo-terminal) spawning for MoonBit native targets, integrated with moonbitlang/async.
Dependencies
let pty = @pty.Pty::spawn(["/bin/sh", "-c", "echo hello"])
defer pty.close()
let reader = pty.reader() // @raw_fd.RawFd
pty.write(@utf8.encode("ls\n")) // async
pty.resize(120, 40)
let pid : Int = pty.pid()try {
@pty.Pty::spawn(["/bin/missing"])
} catch {
err is @os_error.OSError if err.is_ENOENT() => ...
err => raise err
}| Platform | Method | Why |
|---|---|---|
| macOS | openpty() + posix_spawn() self-helper | fork() crashes in mimalloc's atfork child handler |
| Linux | forkpty() + execvp() | Direct fork works (no macOS malloc zone mechanism) |
| Windows | ConPTY + CreateProcessA() | No fork involved |
| Variant | Without runtime | With libmoonbitrun.o |
|---|---|---|
| forkpty() on main thread | works | child exits 139 (SIGSEGV) |
| forkpty() in a pthread | works | child exits 139 (SIGSEGV) |
| posix_spawn() self-helper | works | works |
| MoonBit release without mimalloc | works | n/a |
type PtyCross-platform PTY (pseudo-terminal) spawning for MoonBit native targets, integrated with moonbitlang/async.
Dependencies