0

I have the following script file, which executes a Java main class and print some log data on the terminal. I want to redirect whatever prints this program to another terminal (for example /dev/pts/1, but that didn't work for me). How to do it ?

#!/bin/sh

# Usage: ./zipfs_mount.sh file.zip /mount/point

. ./build.conf

LD_LIBRARY_PATH=./jni:$FUSE_HOME/lib $JDK_HOME/bin/java \
   -classpath ./build:./lib/commons-logging-1.0.4.jar \
   -Dorg.apache.commons.logging.Log=fuse.logging.FuseLog \
   -Dfuse.logging.level=DEBUG \
   Main -f -s $2 $1 > /dev/pts/1
TheForbidden
  • 1,533
  • 4
  • 22
  • 30
  • I'd advise that if it is possible, change the Java program to use a proper logging framework. Logging to stderr is bad practice... If it is not possible, well, you could redirect the output to a file and `tail -F` that... Though you'd have to implement a mechanism to purge the file from time to time to make a limit on the size. – ppeterka Mar 29 '13 at 10:18

1 Answers1

0

What you have written should work, assuming that the program writes its log to stdout rather than stderr and that /dev/pts/1 is the correct device for the other terminal. You can test this with something like:

echo Hello > /dev/pts/1

This should make Hello appear in the other terminal window. If it doesn't, check which device the terminal is using with the tty command.

If your program logs to stderr, you can redirect it too:

program >/dev/pts/1 2>&1     # send stderr to the same place as stdout
Joni
  • 108,737
  • 14
  • 143
  • 193