0

Here I have one command which is like interactive mode:

obex_test -b $BD_ADDR $CH_NUM

This command is from a script but I want to run this command through a system call in a C program. obex_test is nothing but obex file transfer library. Here I want to receive a file from remote device to local device through bluetooth. This is the manual page of obex_test

Please can anybody tell me how can I put my C program in interactive mode like this command, and I want to use this command also.

I used popen(command,"r") but its not useful; it does not take input from the user. If I used "w" mode then I don't know what happens; I directly get a message like >Unknown Command. It's the error this command gives when we give different options. So it's taken something as a write mode.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
user1089679
  • 2,328
  • 8
  • 41
  • 51

2 Answers2

1

You could have two pairs of pipes (created with the pipe(2) system call); one for data from your program to obex_test's stdin and one from obex_test's stdout to your program. Then you would fork and execve... Beware of deadlocks (your program blocked on writing to obex_test stdin when its output pipe is full and blocking it), you might need to call poll(2) or select(2)...

However, as it man pages explain, "obex_test is a test application for the libopenobex library". So why don't call directly functions inside this libopenobex library, which you would link to your program?

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • Can u give me any Example of this pipe concept? please Explain me i am beginner – user1089679 Jan 27 '12 at 07:35
  • Read any standard book on Linux or Unix programming to learn more about pipes, processes, .... But in you case, I strongly suggest using the `libopenobex` library; For unix programming http://basepath.com/aup/ and for Linux programming http://www.advancedlinuxprogramming.com/ – Basile Starynkevitch Jan 27 '12 at 08:38
  • oki i will go with library way. i will find openobex library and have to change this thing. – user1089679 Jan 30 '12 at 04:29
-1

You can use the system command. Check the manual page for more details. For e.g. system( "obex_test -b 172.16.7.1 1234" );

Jack
  • 1