Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Process.output #1235

Merged
merged 1 commit into from
Nov 30, 2018
Merged

Add Process.output #1235

merged 1 commit into from
Nov 30, 2018

Conversation

DanSnow
Copy link
Contributor

@DanSnow DanSnow commented Nov 28, 2018

Depend on #1234
Related #1216

@hayd
Copy link
Contributor

hayd commented Nov 28, 2018

This needs tests. Should there also be a corresponding error function?

Is this the way/func-name Go uses? Python has .communicate to wait and return (out, err)...

@ry
Copy link
Member

ry commented Nov 30, 2018

I've rebased and cleaned up this PR.

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thanks!

@ry ry merged commit d43a4be into denoland:master Nov 30, 2018
ry added a commit to ry/deno that referenced this pull request Nov 30, 2018
- Allow async functions in REPL (denoland#1233)
- Handle Location header relative URI (denoland#1240)
- Add deno.readAll() (denoland#1234)
- Add Process.output (denoland#1235)
- Upgrade to TypeScript 3.2.1
- Upgrade crates: tokio 0.1.13, hyper 0.12.16, ring 0.13.5
@ry ry mentioned this pull request Nov 30, 2018
@@ -59,6 +61,21 @@ export class Process {
return await runStatus(this.rid);
}

/** Buffer the stdout and return it as Uint8Array after EOF.
* You must have set stdout to "piped" in when creating the process.
* This calls close() on stdout after its done.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a somewhat questionable design choice IMO... It's begging for resource leaks.
Let's say the process fails ... now the user has to remember to explicitly close the pipe.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The close is in a try-finally block, so I believe that would actually work. But yes, it's a debatable behavior....Go's cmd.Output does not close the pipe, https://golang.org/pkg/os/exec/#Cmd.Output but in Go you specify the pipe explicitly where as here the system creates the pipe for you...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We definitely need to make a second pass at the subprocess API.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The close is in a try-finally block, so I believe that would actually work

That's not what I mean.
The problem is that the user needs to call output() at all, otherwise the handle leaks.
In many cases there'd be no point in calling output() if the process failed.

ry added a commit that referenced this pull request Dec 1, 2018
- Allow async functions in REPL (#1233)
- Handle Location header relative URI (#1240)
- Add deno.readAll() (#1234)
- Add Process.output (#1235)
- Upgrade to TypeScript 3.2.1
- Upgrade crates: tokio 0.1.13, hyper 0.12.16, ring 0.13.5
@ry ry mentioned this pull request Dec 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants