Replies: 2 comments
-
Something like this? async function prefix(proc, prefix) {
proc.stdout.setEncoding('utf8')
for await (let chunk of proc.stdout) {
process.stdout.write(prefix + chunk)
}
}
$.verbose = false
let a = $`while true; do echo Aaa; sleep 1; done`
let b = $`while true; do echo Bbb; sleep 5; done`
await Promise.all([
prefix(a, '[a] '),
prefix(b, '[b] '),
]) Outputs:
|
Beta Was this translation helpful? Give feedback.
0 replies
-
Or you can apply a middleware transformer: const addOutputPrefix = (prefix) =>
new Transform({
transform(chunk, encoding, callback) {
callback(null, prefix + String(chunk))
},
})
const p = $`cmd`
.pipe(addOutputPrefix('[A] '))
.pipe(process.stdout) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'd like to run a few, long running tasks at once.
Each of them outputs lots of logs I'd like to see in the console.
I can do
and this works fine, but then all logs from various processes are mixed together.
I'd like to do something like
that would result in logs from
foo
egHello world
to be displayed as[A] Hello world
.Beta Was this translation helpful? Give feedback.
All reactions