1

I can do OUTPUT=$(grunt test) and that puts the output into OUTPUT but it's no longer on the screen. I need to see the output as it comes as well, so I can't just wait and then echo $OUTPUT.

How can I capture the output of a program and still have it goto the screen at the same time?

6

You could try something like this:

exec 9>&1
OUTPUT=$(grunt test | tee /dev/fd/9)
exec 9>&-

It copies the current stdout to file descriptor 9, uses tee to replicate grunt's output to that file descriptor, then afterwards closes the temporary file descriptor.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.