shell 如何将星号传递给Deno.command参数之一?

cl25kdpy  于 2023-08-07  发布在  Shell
关注(0)|答案(1)|浏览(83)

我试图从Deno执行shell命令,其中一个参数包含星号。范例:

const output = new Deno.Command("cp", { args: ["source/*", "destination"] }).outputSync()
console.error(new TextDecoder().decode(output.stderr))

字符串
它产生:

cp: cannot stat 'source/*': No such file or directory


如何将星号传递给Deno.Command参数之一?

pxyaymoc

pxyaymoc1#

Deno使用Rust的std:process::Command
注意,参数不是通过shell传递的,而是直接传递给程序。这意味着shell语法,如引号,转义字符,单词拆分,glob模式,替换等。没有效果。
因此,为了使用*,您需要生成一个shell(shbash),正如Glenn Jackman评论的那样。

new Deno.Command("sh", { args: ["-c", "cp source/* destination"] }).outputSync()

字符串

相关问题