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

Is it possible to run subprocess in the background? #9300

Closed
lukejagodzinski opened this issue Jan 27, 2021 · 4 comments
Closed

Is it possible to run subprocess in the background? #9300

lukejagodzinski opened this issue Jan 27, 2021 · 4 comments

Comments

@lukejagodzinski
Copy link

Hey, I've look for the similar problem in stackoverflow and here in the repository but I haven't found anything. I hope it's not a duplicate.

I'm running subprocess command using code like this:

const process = Deno.run({ cmd, stdout: "piped", stderr: "piped" });

const buffer = await process.output();
const str = new TextDecoder().decode(buffer);
console.log(str);

process.close();

The command that I'm running is "persistent"/"not exiting" and it doesn't close but just waits for the connections and then it displays some data to the output. However, Deno expects subprocess to close and then display some data. I've also tried iterating over stdout with Deno.iter but the same effect - nothing is logged to the console.

How can I run "persistent"/"not exiting" subprocess and still be able to get output whenever something is written to stdout?

@nayeemrmn
Copy link
Collaborator

nayeemrmn commented Jan 27, 2021

Detached subprocesses are tracked in #5501. But I think you just don't want to pipe the streams:

const process = Deno.run({ cmd });
await process.status();

@lukejagodzinski
Copy link
Author

Oh so it's not implemented yet. Thanks for info!

And thank you for the suggestion about not piping streams. It's actually a good enough solution for now :) Thanks!

@nayeemrmn
Copy link
Collaborator

I've also tried iterating over stdout with Deno.iter but the same effect - nothing is logged to the console.

This should have also worked. Could you share the code that you used? Otherwise, you can close this issue if everything works.

@lukejagodzinski
Copy link
Author

lukejagodzinski commented Jan 27, 2021

It was something like that:

const process = Deno.run({ cmd, stderr: "piped", stdout: "piped" });
for await (const buffer of Deno.iter(process.stdout)) {
  const str = new TextDecoder().decode(buffer);
  console.log(str);
}
process.close();

It would probably work if I didn't pipe. Closing this issue. Thanks again!

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

No branches or pull requests

2 participants