【问题标题】:Why does deno's exec package execute commands without outputting messages to the terminal?为什么 deno 的 exec 包执行命令时没有向终端输出消息?
【发布时间】:2021-09-06 20:17:41
【问题描述】:
import { exec } from "https://deno.land/x/exec/mod.ts";

await exec(`git clone https://github.com/vuejs/vue.git`)

当我在 .sh 文件中使用 git clone https://github.com/vuejs/vue.git 时,终端中有消息, 但在 deno 中没有

【问题讨论】:

  • exec 模块与 Deno 无关。 https://deno.land/x/... 的所有模块都是第三方代码。要使用您的 shell,请参阅手册中的 Creating a subprocess

标签: deno


【解决方案1】:

首先,我认为回应 jsejcksn commented 的内容很重要:

exec 模块与 Deno 无关。 https://deno.land/x/... 的所有模块都是第三方代码。要使用您的 shell,请参阅 Creating a subprocess in the manual

Deno 在没有第三方库的情况下这样做的方法是使用 Deno.run

话虽如此,如果您查看exec 的自述文件,您会在Capture the output of an external command 下找到您要查找的文档:

有时您需要捕获命令的输出。例如,我这样做是为了获取 git log 校验和:

import { exec } from "https://deno.land/x/exec/mod.ts";
let response = await exec('git log -1 --format=%H', {output: OutputMode.Capture});

如果您查看exec 的代码,您会发现它在后台使用Deno.run。如果你喜欢exec,你可以使用它,但你可能会发现你更喜欢直接使用Deno.run

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-06
    • 2013-07-28
    • 2015-11-20
    • 1970-01-01
    • 2020-06-08
    相关资源
    最近更新 更多