How to call an external exceutable program.

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2008
Posts: 99
Reputation: guest7 is an unknown quantity at this point 
Solved Threads: 0
guest7 guest7 is offline Offline
Junior Poster in Training

How to call an external exceutable program.

 
0
  #1
Jan 4th, 2009
Hi,

I have to call an external executable program (prog2) from within my program (prog1) and then use the output of that exceutable program (prog2) in program (prog1) after calling it.

I have to manipulate the output obtained from progam (prog2) in program (prog1) and then perform this iteration n times.

I do not how to do this. Please let me know.

Thanks
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 670
Reputation: Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough 
Solved Threads: 113
Freaky_Chris's Avatar
Freaky_Chris Freaky_Chris is offline Offline
Practically a Master Poster

Re: How to call an external exceutable program.

 
0
  #2
Jan 4th, 2009
look into pipes

Chris
Knowledge is power -- But experience is everything
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 99
Reputation: guest7 is an unknown quantity at this point 
Solved Threads: 0
guest7 guest7 is offline Offline
Junior Poster in Training

Re: How to call an external exceutable program.

 
0
  #3
Jan 4th, 2009
Hi,

Could you give a small example.

Thanks
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: How to call an external exceutable program.

 
1
  #4
Jan 4th, 2009
  1. /* ************************************* */
  2. /* Function To Run A Shell Command, And */
  3. /* Read The Output Back Into Our Program */
  4. /* ************************************* */
  5. std::string run_command(string cmd)
  6. {
  7. string data;
  8. FILE *stream;
  9. char buffer[1024];
  10.  
  11. // Open The Command With Read Flag
  12. stream = popen(cmd.c_str(), "r");
  13. while (fgets(buffer, 1024, stream) != NULL) {
  14. data.append(buffer);
  15. }
  16. pclose(stream);
  17.  
  18. return data;
  19. }

Usage Case:
  1. // Find Running SSH Daemons In Linux
  2. std::string grepvals = run_command("ps aux | grep \"sshd\"");
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 99
Reputation: guest7 is an unknown quantity at this point 
Solved Threads: 0
guest7 guest7 is offline Offline
Junior Poster in Training

Re: How to call an external exceutable program.

 
0
  #5
Jan 4th, 2009
Hi,

Thanks for the sample code. If possible could you also refer me a book or article online where i can read more about it.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC