How to redirect output of a 'xterm -hold -e' command

11,331

Solution 1

You can turn on xterm logging and send all xterm output to a file:

xterm -l -lf logfile.txt -e program

Solution 2

Redirecting output can change the behavior of programs that run in a terminal. If you want to capture all output of the program use something that does not interfere with the program, e.g., script:

xterm -hold -e script -c "program arguments" output.log

(Linux) or

xterm -hold -e script output.log program arguments

(OSX, other BSD)

Alternatively, you could setup xterm to write its screen to a "printer", e.g., using the printerCommand resource, or using the menu entry Print-All Immediately.

Further reading:

Share:
11,331

Related videos on Youtube

Aeronaelius
Author by

Aeronaelius

Updated on September 18, 2022

Comments

  • Aeronaelius
    Aeronaelius almost 2 years

    I know you can use tee to log output from a command in a terminal, e.g.:

    df -h | tee ~/log.txt

    However, how can I do this with a more complex command like this:

    xterm -hold -e program arg1 arg2 arg3

    I tried this to no avail:

    xterm -hold -e matlab -noxterm -nojvm -r "solver('/path/to/a/folder',1)" | tee ~/log.txt

    My goal is to log all output of the xterm and not of the original terminal. The

    • Sergiy Kolodyazhnyy
      Sergiy Kolodyazhnyy about 9 years
      so you're trying to get output of matlab ?
    • Aeronaelius
      Aeronaelius about 9 years
      I am running MATLAB from the command line in a xterm (not using the GUI). Because my MATLAB code has a bug and is crashing quite severely I want to log everything that is shown in xterm to start debugging.
  • Marius
    Marius over 7 years
    sure - but not everyone has logging configured in xterm, and since OP didn't mention it, must assume it's not in OP's xterm.