Feature request: callback to know when the sub-process is started, of why it failed to exec
@deepak1556 ci sta già lavorando.
Dal 19/12/2025.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
Environment details
- OS: GNU/Linux
- OS version: 16.04
- node-pty version: master
Issue description
When using the spawn function, I didn't find any way to know when the process has been successfully started, or if the exec failed for some reason. My concrete use case is that I need to start a process on a pty. On success, I need to report to the caller that the process has been started*. On failure (e.g. if the executable doesn't exist), I should return the error code. I haven't found a way to do this using the current API.
I have implemented something in our fork of node-pty here, but unfortunately my employer doesn't want me to sign the Microsoft CLA, and thus I can't contribute it. But I thought I would share the idea, to get some feedback. And if somebody wants to implement something similar in the upstream repo, I guess you can't copy the code but you can get some good inspiration from it.
In my patch, I add an exec event to the IPty/ITerminal interface, with an optional error parameter. If the exec goes well, the exec callback is invoked without parameter. If there is an error, it is invoked with an errno string (e.g. ENOENT).
On Linux/macOS, since we use fork + exec to spawn a new process, it's a bit difficult to get some feedback on the exec (since it happens in a new process). I looked at how libuv does (what node's child_process.spawn relies on) and did something similar, which is to use a pipe between the child process and our process to report success or failure.
For Windows, it looks like we just need to catch an exception on failure, here's what I did.
Any feedback is appreciated, and if anybody is willing to work on an upstream version of this, I would be happy to help.
- My criterion for "started" just means that the exec system call returned "success". Many things can go wrong after that, like dynamic libraries not found, but that's out of scope here.
- Lingua principale
- TypeScript
- Stelle
- 2k
- Fork
- 337
- Merge medio
- 21h 58m
- PR unite (30g)
- 3
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di microsoft/node-pty
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
-
Windows: conin socket has no 'error' listener, so a failed pty write is an uncaught exception Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
Tutte le issue di microsoft/node-pty
Issue simili
-
VerificationGate: ATTRIBUTION quote guard never matches a normal quotation (\b around the quote) Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
danielmiessler/LifeOS#2234 ·
-
T: Bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
-
Mend: dependency security vulnerability untriaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100