Propose changes to the Deno.run() API #9435
Replies: 18 comments 6 replies
-
You used a string for cmd here as option; so I assume this means a command with args can be created like this? const cmd = new Command({
cmd: "ls",
args: ["-A"],
env: { ... },
); And just the options in general; since Rust's std and tokio use a builder pattern how do we do the options? still an options bag? Also, do we keep |
Beta Was this translation helpful? Give feedback.
-
Also the program (cmd) always has to be present right, so why not make that positional? Think it was a mistake to stick that in the options bag for Deno.run and I'd like to fix it if we're revisiting 😄 |
Beta Was this translation helpful? Give feedback.
-
Actually not, I think the current |
Beta Was this translation helpful? Give feedback.
-
I feel like this should be |
Beta Was this translation helpful? Give feedback.
-
We should avoid this one; I think it's an antipattern in JS. It can be done with |
Beta Was this translation helpful? Give feedback.
-
Not sure I understand, the crux of this method is that it's sync and won't wait for process completion, currently there's no way in Deno API to check if process has already finished.
What's wrong with |
Beta Was this translation helpful? Give feedback.
-
Yeah - agree. Polling is very much an anti-pattern. |
Beta Was this translation helpful? Give feedback.
-
const maybeStatus = null;
subprocess.wait().then(status => {
maybeStatus = status;
});
// check if subprocess has completed
if (maybeStatus != null) { ... } |
Beta Was this translation helpful? Give feedback.
-
@nayeemrmn that's not really equivalent - calling |
Beta Was this translation helpful? Give feedback.
-
So is there no way to asynchronously listen for subprocess exit without closing stdin? |
Beta Was this translation helpful? Give feedback.
-
I believe so, at least that what |
Beta Was this translation helpful? Give feedback.
-
During the re-architecture of the API, I hope you'll consider adding some way to bypass command and argument processing (quoting, etc). Currently, it's impossible to execute certain valid Windows command lines in Deno. For example, C:>cmd /d/c "deno eval -T "console.log('a string')""
Check file:///C:/Users/Roy/OneDrive/Projects/deno/$deno$eval.ts
a string when implemented via await Deno.run({cmd: ['cmd', '/d/c', '"deno eval -T "console.log(\'a string\')""']}).status();
// => `The system cannot find the path specified.` or ... await Deno.run({cmd: ['cmd', '/d/c', 'deno eval -T "console.log(\'a string\')"']}).status();
// => `error: Unterminated string constant at file:///C:/Users/Roy/OneDrive/Projects/deno/$deno$eval.ts:1:0` It's not possible to construct this command line because the inner double quotes are escaped, which, in turn, breaks the interpretation by In part, this is because Deno is implemented in Rust, which has the same (unresolved) problem with |
Beta Was this translation helpful? Give feedback.
-
While we're looking at this API, I really like Golang's type Command struct {
// ...
Stdin io.Reader
Stdout io.Writer
Stderr io.Writer
} |
Beta Was this translation helpful? Give feedback.
-
Just wanted to make sure that this issue #5501 stays a part of the discussion. Having a |
Beta Was this translation helpful? Give feedback.
-
Rather unorganized notes from last subprocess meeting https://gist.github.com/569dc7d20e1841a84cf89e2bd7dc3f6c |
Beta Was this translation helpful? Give feedback.
-
Bert/Luca/Ben/Ryan agreed that it would be nice if no zombies are left after deno exits, unless the user opts in to |
Beta Was this translation helpful? Give feedback.
-
When the processes is killed when the parent is killed it makes it difficult to use a Native Messaging host to start and stop a local server without keeping the Native Messaging host process open. This sends a single message to the Deno Native Messaging host
Unfortunately when the parent Native Messaging host exists the local server exists - unless I am missing some way to keep the child process open when the parent process closes.
|
Beta Was this translation helpful? Give feedback.
-
Not sure how high level this api is meant to be, but would it be possible to allow full commands as strings? I.e. 9 out of 10 times when I need subprocess functionality, it's to just run a simple command and then get its output as text. Something like: const currentBranch = await runCmd("git branch --show-current"); It would be nice to have the new api be a bit closer to this. Maybe something like: const cmd = new Deno.Command("git branch --show-current");
const currentBranch = await cmd.text(); Ideally Not sure if this is too high level, perhaps this is more suitable for deno_std. |
Beta Was this translation helpful? Give feedback.
-
Given unintuitive way of
Deno.run()
API usage I think we should consider changing that API for Deno 2.0.Tokio provides a great abstraction for running subprocess by the means of
Command
andChild
APIsespecially if user wants to just run process to completion or run it to completion while collecting output.
Currently Deno APIs requires users to handle both situations manually; and I believe it's worth considering to add some helper methods.
Hereby I propose to align Deno's subprocess APIs to follow Tokio's API as closely as possible.
With the proposed changes to the API all appropriate resources used to facilitate subprocess
would be automatically cleaned up (especially stdio resources), meaning that for the most popular
use cases users wouldn't have to remember to call
Deno.close()
on the resources.For more advanced use cases (eg. streaming data from stdout/stderr) there wouldn't be much difference
in the API usability besides changing API names.
Beta Was this translation helpful? Give feedback.
All reactions