user1089679 user1089679 - 1 year ago 74
Linux Question

How can I check for successful execution of last call of system()

Here I want to know the status of the last executed call of


I have one script file containing

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

I want to do same thing in a C Program so I used
to run the command
hciconfig hci0 &>
. But how can I know the status of this executed command? In the shell script we used "$?" same here In C: How can I know whether the last command was executed successfully or not?

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

Answer Source

To quote man 3 system:

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download