LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 12: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, 12: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, 12:41 PM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
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



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

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

All times are GMT -5. The time now is 03:09 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