You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为什么Deno的exec包执行命令时不会向终端输出消息?

问题原因

  • 你使用的第三方exec库默认会把子进程的标准输出(stdout)、标准错误(stderr)内容缓存到返回结果中,不会默认实时输出到当前终端
  • git clone的进度、日志类信息默认输出到stderr而非stdout,哪怕配置了仅输出stdout也看不到相关内容
  • 直接在shell脚本中运行命令时,shell默认会将子进程的stdout、stderr继承绑定到当前终端,所以可以直接看到输出

解决方法

方法1:给第三方exec方法添加输出配置

给exec传入第二个参数开启输出即可:

import { exec } from "https://deno.land/x/exec/mod.ts";

await exec(`git clone https://github.com/vuejs/vue.git`, {
  output: true
})

该配置会自动把子进程的stdout、stderr都同步输出到当前终端。

方法2:使用Deno原生子进程API(更稳定)

更推荐直接用Deno内置的Deno.run实现,可控性更高:

const process = Deno.run({
  cmd: ["git", "clone", "https://github.com/vuejs/vue.git"],
  stdout: "inherit", // 将子进程标准输出绑定到当前终端
  stderr: "inherit" // 将子进程标准错误绑定到当前终端
})

// 等待命令执行完成
await process.status()
// 手动关闭进程实例
process.close()

内容的提问来源于stack exchange,提问作者hewc

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.05 14:39:02