6

Imagine I have a command that produces lots of output and a return code, and I need to run it frequently (e.g. every minute) in a loop.

Is it possible to send the output of the command to a different tmux pane? Then I could split the current pane and see the long output (scrollable) in one of them and a list like 10:00 - Returned 7 \n 10:01 - Returned 5 \n 10:03 - Returned 9 in the current one.

So far, I've only found ways to execute commands in different tmux panes, which is not what I need. I need just a way to pipe the output of the command to another pane which then displays it.

Bowi
  • 1,637
  • 2
  • 20
  • 41

1 Answers1

3

With the help of @Kamil Maciorowski, I've figured it out:

The main thing to learn is: I can pipe into another tty; anything I pipe there, will appear there.

With my Cygwin, I have to adapt this answer, since piping to the fd of the shell's process just gives me errors; instead, I have to look where the fd symlink actually points at – piping there is no problem.

  1. Get the shell's PID:

     echo $$
    
  2. Look where its fd points at:

     $ ls -l /proc/<PID>/fd/1
    
  3. From the resulting string like lrwxrwxrwx 1 ... ... ... ... /proc/<PID>/fd/1 -> /dev/pty4 take the last bit and you know where to pipe to.


Put together:

This alias tells the path where to pipe to for having the output in the current pane:

    alias nameOfCurrentTTY='ls -l /proc/`echo $$`/fd/1 | sed "s/^.* -> //"'

Update/extension: When using bash, it is possible to display the current shell (eg. pty2) in the prompt by adding \l to it (source).

Bowi
  • 1,637
  • 2
  • 20
  • 41