piotrmurach / tty-command

Execute shell commands with pretty output logging and capture stdout, stderr and exit status.
https://ttytoolkit.org
MIT License
400 stars 32 forks source link

Is it possible to 'watch' for changes? #49

Closed 9mm closed 6 years ago

9mm commented 6 years ago

I don't quite know the exact terminology, but is it possible to detect changes when long running commands change the output on the screen?

For example when you run ffmpeg it replaces the existing output (rather than appending lines to the output) each frame it renders. I want to detect every time it changes the output if possible.

I thought it might be stored as the result but when I do output.to_s I just get "0". I am thinking maybe this is because the terminal command things the warnings generated by ffmpeg are errors maybe? Can I ignore the errors, or somehow access the output even when theres errors? Thanks

piotrmurach commented 6 years ago

Thanks for using the library!

Currently, there is no direct method to help you watch for changes. However, the run yields stdout and stderr streams each time something appears in them. A lot of unix tools provide diagnostic output on stderr rather than stdout so I would check there as well.

For example, wait call checks for a pattern in order to know when to terminate the script. You could implement a similar method called watch that if a particular pattern is matched notifies you. Looking forward to a PR if you implement something!

9mm commented 6 years ago

oh ok, thanks, that makes sense. I actually didn't notice I could use just .out and split the output on new lines. Doh!