命令运行后等待的指令会以其答案而死亡。 德夫服务器需要相反的 : 启动、 离开它、 返回输出。 这就是终端在这里的特性 。
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()表面表面
| 调用 | 功能 |
|---|---|
| terminals.list() | 哪些是开放的。 |
| terminals.get(id) | 其中一个 |
| terminals.create({ name, cwd, command }) | 打开一个外壳,可以选择同时运行某些东西。 |
| terminals.remove(id) | 关闭一个。 |
| terminal.run(line) | 发送命令。 |
| terminal.output({ since }) | 印刷的,从一个冲销。 |
| terminal.interrupt() | Ctrl+C - 停止命令,保留外壳。 |
| terminal.kill() | 贝壳结束。 |
他们生活在运行着 SDK
重新启动您的程序, 所有的终端都不见了
他们是你过程的子孙,而不是机器的子孙。一个从一个服务器开始的Dev服务器在持有它的过程离开时就死了,包括以监视模式重新装货。
有两个后果值得设计:二审你的应用程序有自己的终端,无法看到第一个终端,终端不能用来在完成后继续运行。
千万不要写给忙着的贝壳
贝壳一次运行一个命令。 发送行时, 输入输入文本到读 Stdin 的文本, 即是一个提示、 编辑或者什么都没有 。
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")随时间来读取输出
output({ since }) 返回从偏移处打印的内容, 所以投票是一个循环, 与移动的光标连接, 而不是重读一切 。
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, 不是终端模拟器
| 工程 工程 | 没有 |
|---|---|
| 普通命令、 建筑工具、 服务器 | 重新拖放的全屏幕界面 |
| Ctrl+C, 通过中断 () | 需要真正终端的交互式提示 |
| 千瓦以下的 cd 湿重 | 普通颜色和光标控制 |
坚持终端程序会说这样的话或行为古怪。 更喜欢这种工具几乎总是有非交互式的旗帜。
只一台计算机
任何其它的调 storage_not_local 包括没有自己壳壳的电话。 贝壳桥,然后一个代理 bash 那边也是