LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-15-2005, 10:07 AM   #1
OpsVentus
LQ Newbie
 
Registered: Jan 2004
Location: Nijmegen, the Netherlands
Posts: 17

Rep: Reputation: 0
Receiving/sending data from other programs


Hello everyone,

I'm trying to write a program in c++ for Linux and I want to receive data from other program's(wireless-tools) and also call other program's(wireless-tools).
Anyone got an idea how to do this?

Regards Bart.
 
Old 12-15-2005, 09:21 PM   #2
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 12-16-2005, 12:11 AM   #3
viral217
LQ Newbie
 
Registered: Dec 2005
Posts: 3

Rep: Reputation: 0
Post

Hi,
I will not get into the C++ specific syntax, but will briefly explain the concepts of Interprocess communication.

Two porcess (i.e. programs) could talk to each other in the following ways:

1. Sockets
2. Pipes
3. Message queues

I guess you have to use one of the above to talk to another program.

To call another program, depends on how much flexibility you have in building the other program. If its totally yours, i suggest, you make it into a shared library and load it at run time.

For calling other processes from your process, i know of 3 ways.

1. Fork() and Exec()
Fork creates a child process from your process. So after the fork() you have two processes with you. (one child and one parent). Exec() just overlays the other process on top of your process. You might want to exec() on the child and keep the parent for monitoring purposes. (the decision is yours)

2. Exec() (no fork)
It just gets the new process on top of your process and you loose your process.

3. System()
It opens a shell and calls your program in that shell and exits. (it internally uses, fork() and exec())

My C++ knowledge is pretty limited and i am not sure of the calls or API that do the above in C++.

I have tried to briefly explain the concepts above and i hope it helps you.

thanks,
Viral
 
Old 12-16-2005, 08:10 AM   #4
OpsVentus
LQ Newbie
 
Registered: Jan 2004
Location: Nijmegen, the Netherlands
Posts: 17

Original Poster
Rep: Reputation: 0
Thanks alot,
I found the system() command in the source code of a front-end program though. I use it now to call the other program and send the output to a file. After that I can read the file.

I don't know if this is a good way to do it, but it works.
sample(for future reference):

//declaration
int iTemp
QFile tmpFile;
QTextStream stream;

//put stats from iwlist in tmp-file
iTemp = system("iwlist eth1 scan > /tmp/iwlist");

//open tmp-file
tmpFile.setName("/tmp/wifiGui-iwlist");
tmpFile.open(IO_ReadOnly);
stream.setDevice(&tmpFile);

//here you can read the file/aka the output of iwlist

//close and remove it
tmpFile.close();
tmpFile.remove();
(uses Qt)
 
Old 12-18-2005, 07:03 AM   #5
viral217
LQ Newbie
 
Registered: Dec 2005
Posts: 3

Rep: Reputation: 0
Yeah,
The code that you showed looks like it will work. But the more elegant way to do it would be...

(Again just the concepts..not the code from me ;-))

1. fopen() the file with the name and location that you want.

2. fwrite() whatever you want to write in it.

3. fread() it and do whatever you want.

Do it this way if you are really particular to do it the 'right' way..else whatever you have shown seems to be good enough.

Cheers,
Viral
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How To Divert Email While Receiving And Sending? kiranprashant Programming 2 09-14-2005 05:21 AM
How To Divert Email While Receiving And Sending? kiranprashant Linux - Newbie 2 09-13-2005 01:51 PM
having 2 Qmail probs - sending and receiving jaymer Linux - Software 1 06-23-2005 11:11 PM
Sending, receiving through the USB interface The_Nerd Programming 5 02-13-2005 02:49 AM
Sending And Receiving Mail Using Pine Bheki Linux - Newbie 1 01-25-2002 07:09 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:43 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration