Я знаю, как перенаправить в файл и использовать tee; на базовом уровне. Так
$ alias outanderr='bash -c "echo stdout >&1; echo stderr >&2"'
# A fake "application" displaying both output and error messages.
$ outanderr 1>file # redirect stdout to a file, display stderr
stderr
$ outanderr 2>file # redirect stderr to a file, display stdout
stdout
$ outanderr 1>file 2>&1 # redirect both to a file, display nothing
$ outanderr | tee file; echo "-- file contents --" && cat file
# redirect stdout to a file, display both (note: order is messed up)
stderr
stdout
-- file contents --
stdout
$ outanderr 2>&1 | tee file; echo "-- file contents --" && cat file
# redirect both to a file, display both
stdout
stderr
-- file contents --
stdout
stderr
Вопрос в том, что написать вместо вопросительных знаков, чтобы получить результат ниже:
$ outanderr ???; echo "-- file contents --" && cat file
# redirect both to a file, display stderr
stderr
-- file contents --
stdout
stderr
Constaints:
- Предполагая Баш.
- Заказ должен быть сохранен в файле.
- Содержимое stderr отображается в режиме реального времени построчно, т.е. без буферизации.
- Можно использовать отдельные файлы сценариев.
- Магия может быть необходима.
outanderrтолько псевдоним, который печатает строку для stdout, а другую - для stderr. Идея (если это возможно) состоит в том, чтобы создать общее решение, которое могло бы работать с любой программой, не изменяя их.
outanderrпрограммой у вас есть?