Un comando ergue e esperat muere con la sua risposta. Un servèrve dev ha bisogno del contrario: incessa, la lascia, torna a sa output.
const pc = await api.storage.get({ id: machineId });
const shell = await pc.terminals.create({ name: "dev", cwd: "myapp" });
await shell.run("npm run dev");
await shell.output({ since: 0 }); // what it has printed so far
shell.busy; // whether a command is still running
shell.cwd; // where it is now — it follows cd
await shell.interrupt(); // Ctrl+C
await shell.kill();pc = api.storage.get(id=machine_id)
shell = pc.terminals.create(name="dev", cwd="myapp")
shell.run("npm run dev")
shell.output(since=0) # what it has printed so far
shell.busy # whether the shell is still running
shell.cwd # the folder it was started in
shell.interrupt() # Ctrl+C
shell.kill()La superficie
| Chamada | Função |
|---|---|
| terminals.list() | Quals s'operò. |
| terminals.get(id) | Uno di loro. |
| terminals.create({ name, cwd, command }) | Abre un shell, optionalmente a rular algo in una volta. |
| terminals.remove(id) | - Close uno. |
| terminal.run(line) | Envia un comando. |
| terminal.output({ since }) | Ce ha imprimit, da un offset. |
| terminal.interrupt() | Ctrl+C — ferma il comando, mantiene la shell. |
| terminal.kill() | Fine la shell. |
Viven nel processo che esegue il SDK
Un servèrder dev inceput a travers uno muore quando il processo che lo sostene usca — incluso su una recarga in modo watch.
Due conseguenze vale la pena disegnare: un second instancia del vostro app ha i propri terminali e non può vedre i primi, e un terminal non è un modo di mantenere in funzione qualcosa dopo che si è fatto.
Nunca scrivi a un guscio che è occupat
Un shell esegue un comandi per volta. L'emissione di una riga mentre uno corre spinge testo in quello che lee stdin — che è un prompt, un editor, o nullo.
if (shell.busy) {
await shell.interrupt(); // or wait, but do not just send
}
await shell.run("npm test");if shell.busy:
shell.interrupt() # or wait, but do not just send
shell.run("npm test")Lectura di output come viene
output({ since }) restituisce ciò che è stato impresso da un offset, quindi il sondaggio è un buco con un cursore in movimento, invece di un releit de tutto.
let seen = 0;
for (let i = 0; i < 60 && shell.busy; i += 1) {
const chunk = await shell.output({ since: seen });
if (chunk.length) { process.stdout.write(chunk); seen += chunk.length; }
await new Promise((r) => setTimeout(r, 500));
}import sys, time
seen = 0
for _ in range(60):
if not shell.busy:
break
chunk = shell.output(since=seen)
if chunk["text"]:
sys.stdout.write(chunk["text"])
seen = chunk["cursor"]
time.sleep(0.5)Piped, non un emulador terminal
| Operàs | Non fa |
|---|---|
| Comandos ordinari, build tools, servers | Interfaces a schermo completo che redesen |
| Ctrl+C, mediante interrupt() | Provoca interattivo che necessita di un terminale real |
| cwd che segue cd | Colori e control del cursor, in general |
Un programma che insiste su un terminale dicir o comportar curi. Preferir le bandies non interattive tali utensili quasi sempre ha.
Un computer solamente
Qualcosa di altre cose suscita storage_not_local — compreso un telefono, che non ha shell propria. Una pagina può essere dat uno a través o ponte shell, e poi un agent ha bash là.