tee

Cheat sheet exhibiting bash shell stdout/stderr redirection behavior

Is there a good cheat sheet demonstrating the many uses of BASH shell redirection? I would love to give such a thing to my students. Some examples I'd like to see covered: cmd > output_file.txt #redirect stdout to output_file.txt cmd 2> output_file.txt #redirect stderr to output_file.txt cmd >& outpout_file.txt #redirec...

unix `tee` - chain of commands

In a unix environment, I want to use tee on a chain of commands like so $ echo 1; echo 2 | tee file 1 2 $ cat file 2 Why does file only end up as having the output from the final command? For the purpopses of this discussion, let's assume I can't break them apart and run the commands seperately. ...

How to replicate tee behavior in python when using subprocess?

I'm looking for a Python solution that will allow me to save the output of a command in a file without hiding it from the console. FYI: I'm asking about tee (as the Unix command line utility) and not the function with the same name from Python intertools module. Details Python solution (not calling tee, it is not available under Wind...

Is the order that tee prints to stdout guaranteed?

You can split a pipe using the tee command under linux as follows printf "line1\nline2\nline3\n" | tee >(wc -l ) | (awk '{print "this is awk: "$0}') which yields the output this is awk: line1 this is awk: line2 this is awk: line3 this is awk: 3 My question, is that order of printing guaranteed? Will the tee split pipe that counts th...

Perl, redirect stdout but keep on parent

In perl, after fork()ing I can redirect a child's stdout to a file like so open STDOUT,">",$filename or die $! I'm wondering if there is a way of "copying it", keeping the stdout on the parent's stdout but also copying to a specified file. It should happen in a way that would not require any buffering and the user would see the consol...

PowerShell removing console message colors when using tee-object

Is there any way to stop PowerShell from removing console message colors when using tee-object? When I run without tee-object I get the nice error and verbose powershell message colors like this: powershell.exe -noprofile -file $project_root/test_main.ps1 However, when I'm using tee-object (b/c I want logging to console & file), th...

Why does fgets(STDIN, 1024) not work anymore?

Question 1 I used to use that line for my PHP parser file for a game server, but it does not work anymore. I know there is the fopen("php://stdin") thing but that's now 3 lines of code instead of just one, why would PHP do this? Question 2 Also, when I use that method I keep getting this output which is causing my script to not read t...

Writing to multiple file descriptors with a single function call

I had a use case for a group chat server where the server had to write a common string to all clients' socket. I had then addressed this by looping through the list of file descriptors and writing the string to each of the file descriptors. Now I am thinking of finding a better solution to the problem. Is it possible to do this by a sin...

Inspect stdout from the middle of chained apps

Consider this example chain: cat foo.txt | grep -v foo | grep -v bar | grep -v baz I'd like to inspect the contents stdout of the second grep as well as the resulting stdout: cat foo.txt | grep -v foo | grep -v bar | UNKNOWN | grep -v baz So I need a tool, UNKNOWN, that for instance dumps the contents of stdout to a file and also p...

how itertools.tee works, can type 'itertools.tee' be duplicated in order to save it's "status" ?

All, pls see below test code about itertools.tee: li = [x for x in range(10)] ite = iter(li) ================================================== it = itertools.tee(ite, 5) >>> type(ite) <type 'listiterator'> >>> type(it) <type 'tuple'> >>> type(it[0]) <type 'itertools.tee'> >>> >>> list(ite) ...

Force `tee` to run for every command in a shell script?

I would like to have a script wherein all commands are tee'd to a log file. Right now I am running every command in the script thusly: <command> | tee -a $LOGFILE Is there a way to force every command in a shell script to pipe to tee? I cannot force users to add appropriate teeing when running the script, and want to ensure it log...