MrBool
Posts: 118
Joined: Sat Jul 05, 2014 9:51 am

printf on the HDMI console

Wed Oct 28, 2020 6:25 am

I'm using Raspbian Lite. My default console is serial port now and I want to use printf also on HDMI console.

How I can use printf to work also on the HDMI console?

User avatar
jojopi
Posts: 3354
Joined: Tue Oct 11, 2011 8:38 pm

Re: printf on the HDMI console

Wed Oct 28, 2020 7:30 am

printf() writes to standard output, which will normally be the terminal where you started your program. You can open other devices with fopen() and write to them with fprintf().

"/dev/tty0" (zero) represents the currently-active virtual console, which will be visible over HDMI if no GUI is running. You will need to be root or a member of the tty group to open the device for writing.

User avatar
jahboater
Posts: 6310
Joined: Wed Feb 04, 2015 6:38 pm
Location: Wonderful West Dorset

Re: printf on the HDMI console

Wed Oct 28, 2020 12:01 pm

What does /dev/tty represent?
It works for me without root privilege when writing to a terminal window or an ssh window.
Not tried to an HDMI console though.
Pi4 8GB running PIOS64 Lite

User avatar
jojopi
Posts: 3354
Joined: Tue Oct 11, 2011 8:38 pm

Re: printf on the HDMI console

Wed Oct 28, 2020 12:32 pm

jahboater wrote:
Wed Oct 28, 2020 12:01 pm
What does /dev/tty represent?
That is your controlling terminal. Usually the same as your stdin, stdout, stderr. If all of those have been redirected you can still use /dev/tty to get back to the terminal.

Your controlling terminal is the one where the user can hit Ctrl+C to send a SIGINT, etc. You only have one controlling terminal.

This thread, as I read it, is about running on a serial (or network) terminal but wanting to also write to the terminal of the system console which appears on HDMI.

MrBool
Posts: 118
Joined: Sat Jul 05, 2014 9:51 am

Re: printf on the HDMI console

Wed Nov 04, 2020 10:29 am

jojopi wrote:
Wed Oct 28, 2020 7:30 am
printf() writes to standard output, which will normally be the terminal where you started your program. You can open other devices with fopen() and write to them with fprintf().

"/dev/tty0" (zero) represents the currently-active virtual console, which will be visible over HDMI if no GUI is running. You will need to be root or a member of the tty group to open the device for writing.
Thank you for your reply. It works!

Return to “C/C++”