Using tee-object with the output from an exe

Will Pittenger 281 Reputation points
2022-05-05T02:09:37.377+00:00

I'm trying to record the output of yt-dlp to both a log file and see that output on screen. I thought tee would let me do that. I have (yt-dlp something) *>&1 | tee filename.log. It attempts to write the log file only after yt-dlp returns. Plus, nothing appears in the meantime. Do I have something wrong in my PowerShell code?

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,455 questions
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 45,831 Reputation points
    2022-05-05T02:30:57.99+00:00

    What happens if you remove the parentheses surrounding the "yt-dlp something"? Putting that inside parentheses will cause yt-dlp to run to completion (just as any code would because those parens say "do this first") before anything else happens.

    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Will Pittenger 281 Reputation points
    2022-05-05T02:32:19.777+00:00

    It was passing the rest of the line to yt-dlp. Or at least from what I could see. yt-dlp was complaining about a parameter it didn't know: tee.

    0 comments No comments

  2. Rich Matheisen 45,831 Reputation points
    2022-05-05T14:56:40.25+00:00

    Try using an explicit reference to the EXE file. For example (this works):

    PS C:\windows\system32> .\ping.exe 127.0.0.1 | tee c:\junk\x.txt
    
    0 comments No comments

  3. Will Pittenger 281 Reputation points
    2022-05-05T14:58:01.207+00:00

    I don't know why it seemed to be passing all that to yt-dlp. I took the parentheses out and it worked.

    0 comments No comments