How to redirect stderr to a file in a cron job

It’s the other way around: */1 * * * * sudo /home/pi/coup/sensor.py >> /home/pi/sensorLog.txt 2>&1 2>&1 will redirect standard error (2) to standard output (1) which -in turn – was redirected to your log file. So, at the end, both stderr and stdout will go to your sensorLog.txt

How can I capture the stdout from a process that is ALREADY running

True solution for OSX Write the following function to your ~/.bashrc or ~/.zshrc. capture() { sudo dtrace -p “$1” -qn ‘ syscall::write*:entry /pid == $target && arg0 == 1/ { printf(“%s”, copyinstr(arg1, arg2)); } ‘ } Usage: example@localhost:~$ perl -e ‘STDOUT->autoflush; while (1) { print “Hello\n”; sleep 1; }’ >/dev/null & [1] 97755 example@localhost:~$ capture … Read more