Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am writing a shell script and I would like to write commands in the script but redirect the output to other konsole sessions. (using kde)

share|improve this question

migrated from stackoverflow.com Mar 23 '13 at 2:48

This question came from our site for professional and enthusiast programmers.

You can pipe the output to a log file which is tailed by other sessions.

In any other terminal:

touch foo && tail -f foo

In the "main" terminal:

script.sh > foo
share|improve this answer

First, look for the number that identifies the current tty session; lets consider the number as X:

| terminal 1               | terminal 2                |
 ------------------------------------------------------
| $ tty                    | $                         |
| /dev/pts/X               |                           |

Then, use the given number to write to the tty selected:

| terminal 1               | terminal 2                |
 ------------------------------------------------------
| $ tty                    | $ echo "foo" > /dev/pts/X |
| /dev/pts/X               |                           |

And it will produce:

| terminal 1               | terminal 2                |
 ------------------------------------------------------
| $ tty                    | $ echo "foo" > /dev/pts/X |
| /dev/pts/X               |                           |
| foo                      |                           |
share|improve this answer

Print terminal output to file, rather than the terminal your currently in:

commands >>outputfile

In new terminal, use tail to show contents of outputfile and update it automatically as more text is added:

tail -f outputfile
share|improve this answer

Late but maybe better then never... :-)

mkfifo ~/MyOutput           # Create the FIFO (Special file) 

./MyScript.sh > ~/MyOutput  # In the terminal/console 1
cat ~/MyOutput              # In another tty/console

from info coreutils 'mkfifo invocation':

A "FIFO" is a special file type that permits independent processes to communicate. One process opens the FIFO file for writing, and another for reading, after which data can flow as with the usual anonymous pipe in shells or elsewhere.

Side notes:

  • It's better to create the FIFO not in your home directory :-)
  • You can have more than one FIFO for the same process (std out, std err).
  • Untill you will not ask a dump from FIFOs it will hold all the output.
    As you will ask the first time, it will flush out all.
  • You can redirect (or append) to another file cat MyOutput >> NewRealFile
  • You can use cat MyOutput from another terminal too!
  • Warning: If you ask to a 2 diffent programs (or instances) to redirect output to the same FIFOs the flux will be merged (no a priori way to distinguish from which programs that line comes from).
  • Warning: If you ask 2 or more times (maybe from different terminals) it will give one line for each request splitting the output to the requester.
  • It can have more complex uses: How to properly launch a program and make possible to redirect its running output (stdout and stderr) at a later stage?
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.