Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Redirect stdout to file and tee stderr to the same file Ask Question. Asked 1 year, 4 months ago. Active 1 year, 4 months ago. Viewed times.
Improve this question. The thing that's tricky about this is retaining accurate ordering. Just doing the redirection itself is easy, and I'm pretty sure we already have it covered. CharlesDuffy Is it maybe possible with while and read to read the input line by line and determine which should be printed and which shouldn't? Each read operation reads from only one file descriptor. With the above, log will have a copy of both stdout and stderr and I can capture stderr from my script without having to worry about stdout.
At this point the stderr and stdout are not combined yet. In effect, the stderr as stdin is passed to tee where it logs to stderr. And descriptor 3 is logging it to combined. So the combined. Like the accepted answer well explained by lhunath , you can use. Let me take the matthew-wilcoxson exemple. Both message does not appear at the same level. Why Test Out seem to be put like if it is my previous command? Prompt is on a blank line, let me think the process is not finished, and when I press Enter this fix it.
When I check the content of the files, it is ok, redirection works. No prompt on a blank line, but I don't see normal output, stdout. If I relaunch it, output can be different Beware that in bash, this command returns as soon as [first command] finishes, even if the tee commands are still executed ksh and zsh do wait for the subprocesses.
So, if you use bash, prefer use the better exemple given in this other answer :. Now, the question is, how to retrieve exit status code? Thanks lhunath for the answer in posix, Here's a more complex situation I needed in posix with the proper fix:. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow.
Learn more. How do I write stderr to a file while using "tee" with a pipe? Ask Question. Asked 12 years, 9 months ago. Active 1 month ago. Viewed k times. Improve this question. Mark Stewart 2, 4 4 gold badges 22 22 silver badges 31 31 bronze badges. Viewed 91k times. Improve this question. May be the answer looks the same, but it was not the same question. No, it is the exact same question. The first sentence describes what it's trying to do, and it's exactly what you're trying to do: "redirect all output to one file, debug log as well as to the terminal" — phemmer.
Add a comment. Active Oldest Votes. Improve this answer. Stan James 4 4 bronze badges. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Helping communities build their own LTE networks. Podcast Making Agile work for data science.
Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually.
0コメント