I'm having trouble redirecting C printf statements to a file with a program running as root.
I have a program with several informational printf statements and other libraries which print errors via stderr. I'd like to log these to a file. If I start the program from the command line, I can see stderr and stdout messages.
If I try to redirect like so,
sudo ./myprogram >> log_file 2>&1
The log_file only contains stderr, and stdout disappears.
I suspect the issue is related to the root user not being connected to stdout, but I haven't found a solution.
My ultimate goal is to run this program at system start as root, while logging stderr and stdout to a log_file.
I've been trying this using crontab,
sudo crontab -e
and adding the line,
@reboot bin/myprogram >> log_file 2>&1
This generates stderr messages but stdout disappears, same as command line.
Any help is appreciated, thanks!
Edits & updates: Testing this morning, the redirection behaves the same without sudo. A typical printf statement looks like:
printf("info: passed safety check\n");
I'm using a default set up for ubuntu 14.04 on an ARM processor, so I believe I'm using bash. I confirmed with,