user1089679
user1089679

Reputation: 2368

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 system().

I have one script file containing

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

I want to do same thing in a C Program so I used system() to run the command hciconfig hci0 &> /dev/null. 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.

Upvotes: 4

Views: 995

Answers (1)

NPE
NPE

Reputation: 500287

To quote man 3 system:

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

Upvotes: 4

Related Questions