google / zx

A tool for writing better scripts

Home Page:https://npmjs.com/package/zx

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add stdout stream

svennergr opened this issue · comments

Description

This is not a bug, but more of a feature request/enhancement.
I would like to user the stream of the default NodeJS stdout channel, returned from $ calls.

Is there anything I missed or is this currently not possible with zx?

If it is not possible, I am willing to create a PR for that.

This could either utilize generator functions or observables.

Example usecase

I would like to monitor a log file with $"tail -f test.log". With that I would like to react on certain log entries beeing added to the file. For example:

(await $"tail -f test.log").stdout.on("data", (logEntry) =>{
  if(logEntry.includes("error")){
    sendMail()
  }
});

Just a sidethought: this is basically a question, where "zx"'s features stop and basic Node features kick in. I think it's also fine to have such things developed using the standard spawn functionality within Node's child_process.

Zx already supports this. Just drop await keyword.

Awesome, thanks and sorry for not seeing that in the README.

Also here’s an example of stdout/stdin usage within zx: https://github.com/google/zx/blob/main/examples/interactive.mjs

ezoic increase your site revenue