martial
martial

Reputation: 3891

How to not let terminal display anything?

environment: embedded system, linux, c.

Third party modules and my own modules will print information on terminal/console by using printf(). How can I forbid those information being shown on terminal/console? (notice that I cannot comment those printf() since some are in third party modules) Can I set the terminal to a certain mode so that nothing is shown? (something similar to system("stty sane"), maybe?) or do i need to use ioctl()? Please help me...

Thanks a lot!

Upvotes: 2

Views: 320

Answers (2)

Jeff
Jeff

Reputation: 2009

Are you referring to the debug port? If so, you can rebuild the kernel to not have a debug port, or at least disable it.

If you are talking about the shell - that does not make any sense, right? If the shell is disabled, how do you access your device? As Shahbaz says, it's not likely to exist. A better option is to prevent user access to the shell.

Maybe you could explain more about what exactly you are trying to do, and how your device works, or at least how it is accessed.

Update:

Ok - our board has a web interface, we use that (password protected) to enable/disable the ssh server that is connected to the debug port. Sounds like that is what you want.

Upvotes: 1

Shahbaz
Shahbaz

Reputation: 47603

If you want not to see the output when your run the program, you can redirect its output like this:

./program > /dev/null

/dev/null is a special device that eats up everything you feed it (like a black hole). > redirects the output (of stdout) to a file. Redirecting the output to /dev/null means everything is written to /dev/null and that doesn't do anything with it, therefore you effectively throw out your output.

If you want to do it in the program itself, you can call freopen and you can reopen stdout to /dev/null, getting the same effect. Like this:

freopen("/dev/null", "w", stdout);

Sidenote: To redirect stderr, instead of > you can use 2> and with freopen, of course you reopen stderr. It's not such a good idea to redirect stderr to /dev/null though, although it maybe helpful to redirect it to a file.

If you want to redirect both stdout and stderr, you can redirect stderr to stdout and stdout to /dev/null like this:

./program > /dev/null 2>&1

(note the order of redirection)

Upvotes: 6

Related Questions