Coder Social home page Coder Social logo

Comments (7)

dsherret avatar dsherret commented on July 27, 2024 2

You're welcome! This is now released in 0.11.0. I'm not sure if there's anything we can do to mitigate this when capturing the output unfortunately.

from dax.

dsherret avatar dsherret commented on July 27, 2024 2

I believe my change in...

b8402df

...should mitigate this issue. I was using async writers everywhere, but it wasn't necessary.

from dax.

dsherret avatar dsherret commented on July 27, 2024

By default, stdout and error are always captured. What may occur is the sub process writes to stdout, stderr, then stdout, but only then does the process running dax start reading which could read all the data in stdout at once, then after all the data in stderr. I don't think there's any way around this since stdout and stderr are two separate pipes. I think the same issue could occur in zx, but maybe the chances are lower because node uses callbacks? https://github.com/google/zx/blob/700bd4cae2ce564aa477b2501b1916c2a9041a85/src/core.ts#L208-L222

if I inherit the streams from the parent process as...

Yeah, if you inherit then it the subprocess will write directly to the deno process's stdout and err, which won't rely on the javascript code waking up and reading from stdout and stderr, storing it, then outputing. If you want to change the default you can do:

import {
  build$,
  CommandBuilder,
} from "...";

const commandBuilder = new CommandBuilder()
  .stdout("inherit")
  .stderr("inherit");
  
const $ = build$({ commandBuilder });

from dax.

andrewbrey avatar andrewbrey commented on July 27, 2024

@dsherret Got it, this makes sense, and I bet you're right in your guess about zx!

Out of curiosity, did you consider making the io streams inherited by default and piped as an option?

Thanks for the info and follow up on this - cheers!

Edit: I just ran a test with zx and it does indeed print in the "correct" order - I bet you're right about it being less likely to happen given how node uses callbacks. I wonder what it would take to make it print out of order....maybe larger chunks of data written at once so it can't flush the whole buffer at once? Anyway, interesting!

from dax.

dsherret avatar dsherret commented on July 27, 2024

Out of curiosity, did you consider making the io streams inherited by default and piped as an option?

I think that would be better because of the existence of the "helper" functions (like $`some_command`.text()) that could automatically change to piped when necessary. I'll do that right now.

from dax.

andrewbrey avatar andrewbrey commented on July 27, 2024

Awesome! Thanks for taking a look at this and as always, thank you very much for your work on this (and the Deno ecosystem) 😄

from dax.

andrewbrey avatar andrewbrey commented on July 27, 2024

Nice! Yea, given my new understanding of how this works, I suspect you're right. I will go ahead and close this issue as "that's just kinda how it works" 😄

Fortunately, the new default provides the behavior I expected intuitively, so that's great! Cheers!

from dax.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.