How to catch all output text in c

That's my problem. I am working on a unit testing class for a C project. The unit testing class works fine, but one of the methods that it tests calls the method from the API to communicate with a piece of equipment. due to the hardware shutting down the software, there really is no way for me to let it work while I run my tests, and I won’t need to because of the nature of the tests in the black box.

These calls are just char * messages sent to the hardware, and when I run my test, I just get a lot of "Can't contact the API" printouts. which I assume is some kind of error checking in the API part.

My question is that for a good conclusion, in any case, it is possible to catch, suppress or check all the text going to the terminal in this case. (That is, the output stream is correct? I'm new to C)

+3
source share
3 answers

You can also look at the call freopen()to stdout (or stderr) if you link the code that generates these messages. Unfortunately, you are redirecting all program output.

Perhaps you can save the descriptor of the original source, create a channel, call freopen()stdout to redirect to one side of the channel, and also read the stream on the other side, filter the output and send "good" messages to the original original.

+2

, , > . . bash

.

0

, , - (bash ) printf . .

, script.

.

 ~> script appOutputlog.log

 ~> ./app.exe 

, - , , . U Ctrl + D Ctrl + C script. appOutputlog.log , .

2 fopen, fprintf printf s.

3 Another solution is to connect your process to the syslogdone running on your system. This is one of the most standard and production methods for collecting magazines. syslogd- This is a system daemon process designed solely to record the logs of different processes.

0
source

Source: https://habr.com/ru/post/1758059/


All Articles