Reading stdout and stderr of AwesomeWM process

Sometimes you may need to read stdout and stderr of AwesomeWM process, e.g. when you're debugging your plugins. One way to do this is to create a new Xorg instance using Xephyr and launch awesome there, but it may not be very convenient. The other possible way is to trace awesome's write syscalls with file descriptors 1 (for stdout) and 2 (for stderr) using strace and parse out what you need.

Here's a bash script that automates the process.

#!/bin/bash

pid=$(ps -ef | awk '$8=="awesome" {print $2}')
max_str_length=8192

strace -e trace=write -s${max_str_length} -p${pid} 2>&1 \
    | grep --line-buffered --color=no "write([12], " \
    | sed -u 's/write([12], "\(.*\)", [0-9]\+) \+= [0-9]\+$/\1/g' \
    | sed -u 's/\\n/\n/g' \
    | sed -u 's/\\t/\t/g'

Tested with strace 4.25 and awesome 4.2.

If you have any comments, contact me by email.
powered by OpenBSD
© ch1p 2019