Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
OK, after RTFM I know the "function bind" sets "ERROR(s)"on failure ...
1. Can I get such info from the bellow code ?
( I am not asking for specific "ERROR"" just an indicator - in code - that the function sets (stderr) "ERROR".
2. What is most straight forward way to physically retrieve the actual text of the error- assuming it is "stderr"?
I just want to show it , I do not need to log it or otherwise save it into a FILE ( which seems to be most common way ).



C++
/**
   *  @brief Function template for std::bind.
   *  @ingroup binders
   */
  template<typename _Func, typename... _BoundArgs>
    inline _GLIBCXX20_CONSTEXPR typename
    _Bind_helper<__is_socketlike<_Func>::value, _Func, _BoundArgs...>::type
    bind(_Func&& __f, _BoundArgs&&... __args)
    {
      typedef _Bind_helper<false, _Func, _BoundArgs...> __helper_type;
      return typename __helper_type::type(std::forward<_Func>(__f),
					  std::forward<_BoundArgs>(__args)...);
    }


What I have tried:

Unsuccessfully tried starting process and read stderr.
Posted
Updated 6-Mar-24 6:47am
v2
Comments
Richard MacCutchan 6-Mar-24 11:49am    
stderr is an output stream managed by the shell. In normal circumstances it is printed on the terminal window. It is not clear what it has to do with the code you have shown above, or what you mean by, "retrieve".

To begin, you can not rely on any library function to have set stderr to anything. That is one of the three standard handles for input and output. It is not a text buffer so "reading" from it is not a viable option.

The most straight-forward way is to call WSAGetLastError in the windows world and elsewhere it is to pass errno to the function strerror. Here is an article that describes this : How to get socket error message[^]

Richard's comment is correct and your question is really not clear at all.

Normally when one wants to write to stderr you do something like this :
C++
fprintf( stderr, "Error at line %d of %s\n", __LINE__, __FILE__ );
stderr, like stdout, can be redirected to a file also.
 
Share this answer
 
v2
Comments
Dave Kreskowiak 6-Mar-24 14:12pm    
I think he might be trying to read from stderr in his own app.
Rick York 6-Mar-24 15:47pm    
Upon further review, I think you are right. I will revise my answer.
On reflection I guess this is probably related to all your other questions on this subject. A pity you showed that random code in your question that has nothing to do with it, rather than the actual code you are using. As I have suggested more than once including at How do I redirect "system" call output ?[^], you need to use the popen method to read the output of a shelled process. If you want to capture both the normal and error streams, then you need to redirect stderr to stdout in your shell command thus:
Shell
hcitool info 98:D3:31:F8:39:33 2>&1

The expression 2>&1 tells the shell to redirect stream number 2 (stderr) to stream number 1 (stdout), so that all output ends up in the same place: either terminal or redirected again to a file. It is up to you, the user, to separate the messages in the combined output.

The redirection of streams is fully explained in the bash man pages, which I again suggest you read.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900