How does Deno.run "echo hello" cause this file not found error?

Viewed 869

Trying out Deno's standard library, I ran into a problem with Deno.run - a function to spawn a new subprocess.

This example is provided in the documentation:

const p = Deno.run({
    cmd: ["echo", "hello"],
});

Running this using the --allow-run permission, I get the following error:

error: Uncaught NotFound: The system cannot find the file specified. (os error 2)
    at unwrapResponse ($deno$/ops/dispatch_json.ts:43:11)
    at Object.sendSync ($deno$/ops/dispatch_json.ts:72:10)
    at Object.run ($deno$/ops/process.ts:41:10)
    at Object.run ($deno$/process.ts:118:15)
    at file:///C:/Users/.../gitgraph-deno/gitgraph.ts:1:16

js/process.ts:118:15 is a call to run in js/ops/process.ts, which itself calls sendSync in dispatch_json.ts.

The stacktrace says the error originates from dispatch_json.ts line 72. This just unwraps the JSON response received in line 67: const resUi8 = core.dispatch(opId, argsUi8, zeroCopy);.

I think the core.dispatch goes all the way to isolate.rs line 358. That's where I get lost.

TLDR: Somewhere under the hood of Deno this error occurs: The system cannot find the file specified. (os error 2) when I try to Deno.run({cmd: ["echo", "hello"]});.

2 Answers

As posted below by Andrew Dibble: Deno is unable to locate a binary file called echo in my path. Google brought me to an SO answer telling me echo in Windows is just a command internal to CMD. It's not a binary file.

cmd /c allows you to call CMD.exe's internal and external commands.

Taking that into account, I fixed my issue by using:

Deno.run({cmd: ["cmd", "/c", "echo", "hello"]});

Instead of:

Deno.run({cmd: ["echo", "hello"]});


And here's an example to also read the output:

const p = Deno.run({cmd: ["cmd", "/c", "echo", "hello"], stdout: "piped"});
const output = new TextDecoder('utf-8').decode(await p.output());
console.log(output);

Deno is unable to locate a binary file called echo in your path:

$ deno
Deno 1.0.0
exit using ctrl+d or close()
> Deno.run({
    cmd: ["echo", "hello"],
hello
Process { rid: 4, pid: 24264 }

On my Linux machine, the above works fine because I have a program accessible in my path by the name of echo.

I do not however have any program by the name of foo:

> Deno.run({
    cmd: ["foo", "hello"],
});
Uncaught NotFound: No such file or directory (os error 2)
    at unwrapResponse ($deno$/ops/dispatch_json.ts:43:11)
    at Object.sendSync ($deno$/ops/dispatch_json.ts:72:10)
    at Object.run ($deno$/ops/process.ts:45:10)
    at Object.run ($deno$/process.ts:118:15)
    at <unknown>:1:6
    at evaluate ($deno$/repl.ts:45:34)
    at Object.replLoop ($deno$/repl.ts:136:13)

So when I tell Deno to run a program by the name of foo, it is unsurprisingly unable to find where this program lives and start it in a new process.

Unfortunately, I don't know how to fix this in your particular instance because it's very setup specific, but I believe that to be the issue.

Related