1

I'm writing a c-file in linux and I need to put 2 commands in my code but I don't know how to do this.

The commands are

sudo hciconfig hci0 piscan

and

sudo hciconfig hci0 noscan

Thanks in advance

devnull
  • 118,548
  • 33
  • 236
  • 227
Daan Mouha
  • 580
  • 1
  • 6
  • 20

1 Answers1

4

use

system("sudo hciconfig hci0 piscan");

or

FILE *pipe;
pipe=popen("sudo hciconfig hci0 piscan", "r");

to get the output of your command from the pipe, you can use the functions fgets, fread, ... you can read from the pipe like you read from a file

MOHAMED
  • 41,599
  • 58
  • 163
  • 268