Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

non interactive process output to file

Status
Not open for further replies.

perfectrecords

Technical User
Sep 20, 2006
3
GB
Hi There,

Does anybody know of a way in bash shell script to stream the output from a non interactive process (eg sdptool) to a file. At the moment if I try to output the data from an sdptool enquiry it only dumps the data to the file when the enquiry has finished scanning, whereas it would be great if it put the data to the file as it found it.

Thanks in advance

Joe
 
out of interest what command are your running against sdptool ?

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Hello,
the same question was asked a few days ago,
have a look at thread822-1279177
(and yes, it it about sdptool, the poster told this later on.)
 
don't be shy :) I'm intrigued, 2 posts on the same subject and neither with an acceptable answer.

What command are you using against sdptool, what are you looking for, a specific service from a device, or just devices in general?

This for me seems to behave as expected
Code:
sdptool browse |grep "^Browsing\|^Service"

Theres a slighlt delay when it starts, data from teh first device is returned, and then after a (very brief) pause the next devoce returns data.



______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
For the reference of others, I have found a solutions to my problem. It would seem the only way to do this is by editing the sdptool.c file contained within the tools folder of the bluez-utils tarball. The end of the file now looks as follows;

int main(int argc, char *argv[])
{
int i, opt;

setvbuf (stdout, (char *)NULL, _IOLBF, 0);

bacpy(&interface, BDADDR_ANY);

while ((opt=getopt_long(argc, argv, "+i:h", main_options, NULL)) != -1) {
switch(opt) {
case 'i':
if (!strncmp(optarg, "hci", 3))
hci_devba(atoi(optarg + 3), &interface);
else
str2ba(optarg, &interface);
break;

case 'h':
usage();
exit(0);

default:
exit(1);
}
}

argc -= optind;
argv += optind;
optind = 0;

if (argc < 1) {
usage();
exit(1);
}

for (i = 0; command.cmd; i++)
if (strncmp(command.cmd, argv[0], 4) == 0)
return command.func(argc, argv);

return 1;
}

The important line is "setvbuf (stdout, (char *)NULL, _IOLBF, 0);" which sets the buffer for the process to zero. This means as it writes the output it dumps it to the file. This means that once compiled and installed into /bin/sh any command from sdptool will now output the buffer as it is written. I presume this line of code works with all non interactive processes.

Thanks for all your posts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top