Make C Program for Interactive Mode

1.5k views Asked by At

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.

2

There are 2 answers

3
Basile Starynkevitch On

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?

3
Jack On

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" );