【问题标题】:Interactive shell in DenoDeno 中的交互式 shell
【发布时间】:2021-07-14 06:51:14
【问题描述】:

在 python 中,以下行生成一个交互式 shell,我可以像任何终端一样使用它。

os.system("bash");

在此处输入 exit 退出 shell,python 脚本继续执行。

我怎样才能在 Deno 中做这样的事情?

编辑:我最初的问题应该更冗长一些。我的意图不仅仅是运行一个 shell 命令。我想运行一个交互式 shell,它会抓取输入/输出,直到我使用 exit 命令手动退出。 Deno.run({cmd: ["bash"]}) 不会这样做。

【问题讨论】:

标签: deno


【解决方案1】:

您需要等待进程(bash shell)退出。为此,您需要 await process.status()

// run using 
// deno run --allow-run demo.js

const p = Deno.run({
  cmd: ["bash"],
})

const status = await p.status()
console.log(status)

如果你想使用 Deno REPL,那么运行 -

await Deno.run({ cmd: ["bash"] }).status()

【讨论】:

    猜你喜欢
    • 2017-07-15
    • 2020-05-27
    • 2016-02-17
    • 2013-04-16
    • 2011-07-24
    • 2013-08-22
    • 1970-01-01
    • 2011-08-13
    • 2010-10-31
    相关资源
    最近更新 更多