Can you redirect Tee-Object to standard out?

To complement zett42’s helpful answer: If you’re running PowerShell (Core) 7+, you can pass the file path that represents the terminal (console) to the (positionally implied) -FilePath parameter (in Windows PowerShell, this causes an error, unfortunately – see bottom section): # PowerShell 7+ only # Windows Get-Content data.txt | Tee-Object \\.\CON | data_processor.exe # Unix-like … Read more

How can I implement ‘tee’ programmatically in C?

You could popen() the tee program. Or you can fork() and pipe stdout through a child process such as this (adapted from a real live program I wrote, so it works!): void tee(const char* fname) { int pipe_fd[2]; check(pipe(pipe_fd)); const pid_t pid = fork(); check(pid); if(!pid) { // our log child close(pipe_fd[1]); // Close unused … Read more

Get exit code from subshell through the pipes

By using $() you are (effectively) creating a subshell. Thus the PIPESTATUS instance you need to look at is only available inside your subshell (i.e. inside the $()), since environment variables do not propagate from child to parent processes. You could do something like this: OUT=$( wget -q “http://budueba.com/net” | tee -a “file.txt”; exit ${PIPESTATUS[0]} … Read more

How to replicate tee behavior in Python when using subprocess?

I see that this is a rather old post but just in case someone is still searching for a way to do this: proc = subprocess.Popen([“ping”, “localhost”], stdout=subprocess.PIPE, stderr=subprocess.PIPE) with open(“logfile.txt”, “w”) as log_file: while proc.poll() is None: line = proc.stderr.readline() if line: print “err: ” + line.strip() log_file.write(line) line = proc.stdout.readline() if line: print … Read more

Force line-buffering of stdout in a pipeline

you can try stdbuf $ stdbuf –output=L ./a | tee output.txt (big) part of the man page: -i, –input=MODE adjust standard input stream buffering -o, –output=MODE adjust standard output stream buffering -e, –error=MODE adjust standard error stream buffering If MODE is ‘L’ the corresponding stream will be line buffered. This option is invalid with standard … Read more