D
Deno

help

Deno.Command arg with an asterisk?

Bbirgersp7/27/2023
I am trying to execute a shell command from Deno, where one of the command args contains an asterisk. Example:
const output = new Deno.Command("cp", { args: ["source/*", "destination"] }).outputSync()
console.error(new TextDecoder().decode(output.stderr))
const output = new Deno.Command("cp", { args: ["source/*", "destination"] }).outputSync()
console.error(new TextDecoder().decode(output.stderr))
It yields:
cp: cannot stat 'source/*': No such file or directory
Q: How can I pass an asterisk to one of the Deno.Command args?
IioB7/27/2023
The asterisk is a shell-only concept, and not something cp can really do. This is a fundamental "limitation" of the fork-exec call happening here. You'd need to manually enumerate the files yourself:
const source = Deno.readDirSync("source/*").map((entry)=>`source/${entry.name}`)
const output = new Deno.Command("cp", { args: [...source, "destination"] }).outputSync()
console.error(new TextDecoder().decode(output.stderr))
const source = Deno.readDirSync("source/*").map((entry)=>`source/${entry.name}`)
const output = new Deno.Command("cp", { args: [...source, "destination"] }).outputSync()
console.error(new TextDecoder().decode(output.stderr))
alternatively, if you really want to use shell constructs, you can simply call a shell instead
const output = new Deno.Command("sh", { args: ["-c", "cp source/* destination"] }).outputSync()
console.error(new TextDecoder().decode(output.stderr))
const output = new Deno.Command("sh", { args: ["-c", "cp source/* destination"] }).outputSync()
console.error(new TextDecoder().decode(output.stderr))
Bbirgersp7/27/2023
❤️ for helping noobs like me, you are a true hero

Looking for more? Join the community!

Recommended Posts
`deno compile` in Nix results in `deno repl` starting instead of actual programI wrote following Nix impure derivation for my Deno app: ```nix packages.api = pkgs.stdenv.mkDerivat`@sentry/node` is throwing an export error on Deno DeployHello, this is my first time using Deno. I was trying to use the `@sentry/node` client on deploy, basync mapIs there anyway using the stdlib to map from one array to another array, with the work being done coHTTP 206 + HTML5 video streaming with Freshhow do I implement an endpoint to stream a video to a HTML video player using HTTP 206 in Fresh? Herrusty_v8 extracting stack trace when a promise rejectsHi, i am trying to get the stack trace and print it out when a promise rejects. ```rust if promise.sNode-API related segmentation faultAny idea what could be causing this crash? I'm using Node-API and the same module is working fine injwt generation and verificationjwt verification(using JOSE package) is working perfectly only when i have set b64 parameter insideHosting a node project on deploy?Can we host a NodeJS project using Deno Deploy or do we need some conversion first?anyone have a modern container workflow for the serverless framework?I was able to find code that executed at one point in time. It no longer does. I’d really like to iHow to deno up nuxt?**Setting up Nuxt3**: When learning more about V8 and the node.js architecture I became aware of dengoogle cloud SDKsHi all, I am building an application that interacts with google cloud apis, specifically google plaPrisma and denogetting this ```error: could not find package '.prisma' from referrer 'file:///Users/nikos/WebstormP