Pergunta

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
Foi útil?

Solução

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
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top