Cross-platform PTY (pseudo-terminal) spawning for MoonBit native targets, integrated with moonbitlang/async.
Dependencies
@async.with_task_group(group => {
let pty = @pty.spawn(group, ["/bin/sh", "-c", "echo hello"])
defer pty.close()
let reader = pty.reader() // @raw_fd.RawFd
pty.write(@utf8.encode("ls\n")) // async
pty.resize(cols=120, rows=40)
let pid : Int = pty.pid()
let exit_code : Int = pty.wait()
})try {
@async.with_task_group(group => {
@pty.spawn(group, ["/bin/missing"])
})
} catch {
err is @os_error.OSError if err.is_ENOENT() => ...
err => raise err
}| Platform | Method | Why |
|---|---|---|
| macOS | openpty() + moonbitlang/async self-spawn helper | avoids fork() with mimalloc |
| Linux | openpty() + moonbitlang/async self-spawn helper | shares the async process spawn path |
| 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