LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 04-01-2008, 02:10 PM   #1
jboss1995
LQ Newbie
 
Registered: Apr 2008
Posts: 3

Rep: Reputation: 0
How to use c++ to use a command line program


I was wondering how programs like k3b use command line programs like cdrecord, cdrdao, growisofs etc. Do they just use their library's or do they call the programs directly. If so, can you show me a short example. I'm trying to write a program that will use vmstat in a gui. Thanks for your help.
 
Old 04-01-2008, 03:07 PM   #2
Maligree
Member
 
Registered: Mar 2008
Distribution: Gentoo, CentOS, Fedora, Arch
Posts: 231
Blog Entries: 1

Rep: Reputation: 42
Not 100% sure but I took a quick look at k3b's sources and it looks like it uses the console apps directly - since they're even described as "external applications" in the comments. You should take a look at the sources yourself - C++ isn't really my game and neither is Qt so the code isn't completely clear for me but you shouldn't have a problem with it. It's pretty well commented too.

Pretty sure other GUI apps do it the same way - it's easier and faster to use ready-to-go, external apps - the developers can focus on the usability of their program instead actually rewriting an already existing app (as it would happen if they decided to use only the libraries).

I may be wrong, I'm no developer. Yet.

Last edited by Maligree; 04-01-2008 at 03:13 PM.
 
Old 04-02-2008, 08:23 AM   #3
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
You can use either system or execvp (et. al.)
ta0kira
 
Old 04-02-2008, 09:12 AM   #4
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
For many programs, system, or one of the execs with forking is probably sufficient. If you have an interactive command line program, you might find libexpect useful. This allows you to spawn child processes, monitor their output, and interact with them. Expect is a language which extends TCL, but you can use libexpect from C and C++ programs.
 
Old 04-05-2008, 11:22 PM   #5
jboss1995
LQ Newbie
 
Registered: Apr 2008
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by matthewg42 View Post
For many programs, system, or one of the execs with forking is probably sufficient. If you have an interactive command line program, you might find libexpect useful. This allows you to spawn child processes, monitor their output, and interact with them. Expect is a language which extends TCL, but you can use libexpect from C and C++ programs.
This is exactly what i was looking for. Thanks so much.
 
  


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
Command line mail program. kwikness Linux - Newbie 2 05-16-2006 03:03 AM
how to write command line program? vito_huang Linux - Software 3 04-14-2006 01:20 AM
How to program C in Linux command line backpacker Programming 4 06-24-2005 07:57 PM
kill program command line demmylls Linux - General 7 02-09-2004 09:55 PM
Viewing program messages when program isn't run from command line? Locura Linux - Software 1 09-27-2003 09:19 AM


All times are GMT -5. The time now is 08:05 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration