How to verify the success of the last system call ()

Here I want to find out the status of the last call to system() .

I have one script file containing

 hciconfig hci0 &> /dev/null if [ "$?" -ne 0 ]; then . ./$BT_CLEAN 

I want to do the same in a C program, so I used system() to run the hciconfig hci0 &> /dev/null command. But how can I find out the status of this executed team? In the shell script, we used "$?" same thing here In C: How can I find out if the last command was successful or not?

I used system("hciconfig hci0 &> /dev/null") in C.

+4
source share
1 answer

To quote man 3 system :

system() returns -1 on error (for example, fork(2) failed), and return the status of the command otherwise.

+4
source

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


All Articles