I use this command to see output both on console and file:
powershell -command "my_command_1 | tee ('logs\{0}.log' -f (Get-Date -format 'yyyy.MM.dd-HH.mm'))"
powershell -command "my_command_2 | tee ('logs\{0}.log' -f (Get-Date -format 'yyyy.MM.dd-HH.mm'))"
# etc
It works not as good as I expected and I have some questions:
- How to redirect stderr also to file?
- Output works very strange. For some commands there is a huge delay between text is printed and console/file is updated. For some other commands output seems updated when text is printed (I run commands without tee and I know what it should print). This delay makes this tee almost useless - what if some critical error will be printed so I need to stop command, but I won't see anything until it's too late. For some commands output is printed only after full command is done.
- Furthermore, even if command asks user input console/file output is empty! For that command I know what it expects and blindly print needed text and it worked, but for others - with no output I'll wait something to happen infinitely while command will wait my input!
Are there solutions for these issues? If not, this tee thing in Powershell is completely useless.