Tag Info

Hot answers tagged

4

The simplest way I can think of doing this is: ls "$@" | sort | tee >(rev > /tmp/output) The tee will send one copy to STDOUT, and since there is no longer a | after it, this is inherited, meaning it'll go to the TTY if not redirected, and your myfile if it is. The other copy will get sent to rev > /tmp/output on its STDIN. In bash, >(...) ...


4

There is a program to interact with interactive command line tools exactly like the ftp example: expect. It is very powerful, but you may get away without learning everything about it. A very useful tool is autoexpect, which can record an interactive session as an expect script. The recorded script is certainly helpful to understand the basics. I think ...


3

... | tee /dev/tty | ... /dev/tty is the "file" that refers to your terminal.


2

Since the other answer isn’t being clear about this, the other (another) way is exec 3>&1 ls | sort | tee /dev/fd/3 | rev > /tmp/output The exec 3>&1 duplicates file descriptor 1 (stdout) as file descriptor 3.  Then tee /dev/fd/3 writes a copy of sort’s output to that file descriptor.  This should work in any shell, but it may be ...


2

You might use coprocesses. Simple wrapper that feeds both outputs of a given command to two sed instances (one for stderr the other for stdout), which do the tagging. #!/bin/bash exec 3>&1 coproc SEDo ( sed "s/^/STDOUT: /" >&3 ) exec 4>&2- coproc SEDe ( sed "s/^/STDERR: /" >&4 ) eval $@ 2>&${SEDe[1]} 1>&${SEDo[1]} ...


2

I did a strace on both commands. The interessting thing is that when you pipe the output to head there are only 123 system calls. On the other hand when pipeing to tail there are 245 system calls (or more when there are more *.txt files). Case: head Here are the last few lines when pipeing to head: open("file12.txt", O_RDONLY) = 3 fadvise64(3, ...


2

Any process that does not block SIGPIPE will be killed if its output goes to the write end of a pipe that no one is reading from. So as soon as head closes its input (i.e. terminates), wc dies, which takes less time than finishing all the work.


1

The program ag (I'm not familiar with it), could use the system call stdout_is_tty = isatty(1); The isatty() function tests whether fd is an open file descriptor referring to a terminal. This allows it to modify the output depending on where it is writing to. I also think I found the relevant source code section /* If we're not outputting to a ...


1

Method #1. Using file descriptors and awk What about something like this using the solutions from this SO Q&A titled: Is there a Unix utility to prepend timestamps to lines of text? and this SO Q&A titled: pipe STDOUT and STDERR to two different processes in shell script?. The approach Step 1, we create 2 functions in Bash that will perform the ...


1

You can do it using reredirect (https://github.com/jerome-pouiller/reredirect/). reredirect -m /dev/null <PID> You can restore initial output of your process later using something like: reredirect -N -O <M> -E <N> <PID> (<M> and <N> are provided by previous launch of reredirect). reredirect README also explains how ...



Only top voted, non community-wiki answers of a minimum length are eligible