DNA
DNA15mo ago

Deno.Command not working for application

Hello. Im trying to start an application using Deno.Command, but it for some reason doesnt work. The path itself functions normally even from powershell.
// Get the application to start
const application = body.application?.trim()?.replace(/\\/g, "/");
if (!application) return new Response(JSON.stringify({message: "error", error: "noApplication"}), {status: Status.BadRequest, headers: {"Content-Type": "text/json"}});

// If there is a space in the application, surround it with quotes
console.log(application);

const command = new Deno.Command(`${application}`, {stdin: "null"});

// Return the user the code and the time it took to execute
const start = performance.now();
const results = await command.output();
const end = performance.now();

return new Response(JSON.stringify({message: "success", code: results.code, time: end - start}), {status: Status.OK, headers: {"Content-Type": "text/json"}});
// Get the application to start
const application = body.application?.trim()?.replace(/\\/g, "/");
if (!application) return new Response(JSON.stringify({message: "error", error: "noApplication"}), {status: Status.BadRequest, headers: {"Content-Type": "text/json"}});

// If there is a space in the application, surround it with quotes
console.log(application);

const command = new Deno.Command(`${application}`, {stdin: "null"});

// Return the user the code and the time it took to execute
const start = performance.now();
const results = await command.output();
const end = performance.now();

return new Response(JSON.stringify({message: "success", code: results.code, time: end - start}), {status: Status.OK, headers: {"Content-Type": "text/json"}});
5 Replies
abi
abi15mo ago
Are you trying to execute a Windows shortcut? Lol you can’t do that. You need an executable.
DNA
DNA15mo ago
Its an .lnk Idk if thats exactly what you mean In node that previously did work perfectly fine with .lnk's
Leokuma
Leokuma15mo ago
Running a shortcut might work if you pass powershell.exe or cmd.exe as the executable for Deno.Command and the lnk file as the argument
DNA
DNA15mo ago
That works, thank you very much
Leokuma
Leokuma15mo ago
You can also consider use this to simplify running the commands: https://github.com/dsherret/dax
GitHub
GitHub - dsherret/dax: Cross platform shell tools for Deno inspired...
Cross platform shell tools for Deno inspired by zx. - GitHub - dsherret/dax: Cross platform shell tools for Deno inspired by zx.