Code Monkey home page Code Monkey logo

Comments (6)

gahag avatar gahag commented on August 15, 2024 1

Ouch, we have our first bug :). This used to work on previous development versions, but I had to rework the capture code to solve a bug related to redirections, and accidentally introduced this bug while doing so. The issue is that we're reading the pipe after waiting the command to finish, but the command is waiting because the pipe is full. I already have a fix in mind, and will try to implement it until the weekend. Thanks for reporting!

from hush.

Jackman3005 avatar Jackman3005 commented on August 15, 2024

Interesting cause... makes me think about my comment in another issue about being able to read stdout from async capture before joining.

I'd imagine hush will need to support streaming input as bash supports streaming output.

from hush.

gahag avatar gahag commented on August 15, 2024

Talking about that, if I recall correctly, to stream output using bash one would use a named fifo (mkfifo) and then use standard redirection operations to route the data. Something like:

#!/usr/bin/env bash

mkfifo /tmp/webserver.log

webserver --start > /tmp/webserver.log &

while read data < /tmp/webserver.log; do
  # use $data
end

Considering this approach, it makes sense to have the capture block produce a single string instead of streaming the output. What do you think?

from hush.

gahag avatar gahag commented on August 15, 2024

Fixed by 335d5b7, released on v0.1.3-alpha

from hush.

Jackman3005 avatar Jackman3005 commented on August 15, 2024

@gahag

When you pipe in bash I believe it also streams. i.e. I believe that each line of output is sent to the next command in the pipe immediately, it doesn't batch multiple lines.

I think Hush will need to support this or miss out on some common use cases. For example, if I want to tail live server logs and filter lines to print only the ones with errors I can do something like aws logs | grep 'ERROR'. I don't think that currently I can do this in hush with an async capture around the aws logs since the command would never finish on its own.

from hush.

gahag avatar gahag commented on August 15, 2024

But those are two separate features, and both work the same way in Hush and Bash. Capture is synchronous, so it will hang until the command finishes.

#!/usr/bin/env bash
$(mycommand)
#!/usr/bin/env hush
${ mycommand }

Pipes on the other hand are asynchronous, and will allow data streaming.

mycommand | tee file.log | grep Error
{ mycommand | tee file.log | grep Error }

Hush implements the exact same behavior as Bash in both cases.

from hush.

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.