LinuxQuestions.org
Review your favorite Linux distribution.
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 01-25-2005, 01:01 PM   #1
drisay
Member
 
Registered: Sep 2004
Distribution: Slackware 10
Posts: 167

Rep: Reputation: 30
calling external applications in your c++ code


hi all,

just wondering how it was done to call external procedures from a c++ application. eg. how would i go about calling tar or mv or cp or whatever from a c++ app. what libraries would i need to include. i read part of a pdf book on linux programming which brushed over this, but it wasn't quite clear to me where you get the libraries. is it one main one being glibc or are there individual libraries for each app, etc.

thanks,
drisay
 
Old 01-25-2005, 01:34 PM   #2
drisay
Member
 
Registered: Sep 2004
Distribution: Slackware 10
Posts: 167

Original Poster
Rep: Reputation: 30
is fork and exec the way to go?
 
Old 01-25-2005, 01:41 PM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 110Reputation: 110
Functions to do this are in standard library. You don't need to specify some library.

The most simple function way to execute an external program is just: system("/bin/ls");

popen() is another function to execute an external program while capturing the standard output of it into your own program.

The "real" stuff is: fork() in combination with one of the exec()-family of functions.

Please read these man pages for more info:
man system
man popen
man fork
man exec

And here's a freely downloadable book which has an entire chapter on the subject: http://www.advancedlinuxprogramming.com/

You could also search this forum, as it has been asked and answered many times before...
 
  


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
Calling external programs to FTP from C program Manish Programming 11 04-03-2005 11:53 PM
QT newbie - calling external programs squinn Programming 1 03-24-2005 11:23 AM
Bug in c code calling bash code Linh Programming 11 08-12-2003 05:27 AM
Calling long BASH code within a C program Linh Programming 4 06-24-2003 02:41 PM
C program code calling a Linux system command Linh Programming 1 06-05-2003 02:44 PM

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

All times are GMT -5. The time now is 05:53 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration