Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 04-14-2005, 12:08 PM   #1
Registered: Sep 2001
Distribution: Ubuntu, Debian, Gentoo
Posts: 162

Rep: Reputation: 30
C++ Interfacing with command line tools

I am currently trying to understand how to interface with some command line tools in C++. Basically, whenever I am in bash -- I execute some commands to perfrom some action. Let's say that I want to do a par2repair on some file.par2. I would just execute "par2repair file.par2". However, I would like to do the same thing within a C++ application, but have been told that exec() and system() like calls are not good to use (not portable?). Also, how would I parse the data returned by the call to par2repair, for instance, if there was an error? Is there some way to go about doing this? I have not learned this in school, but am trying to develop something on my own which needs this capability. Thank for your input...

Kristian Hermansen
Old 04-14-2005, 12:43 PM   #2
LQ Guru
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
I don't know in C++ but in C there is popen() function from <stdio.h> that
works like a pipe for set input/get output to/from a command

man 3 popen (really easy to use)
Old 04-14-2005, 02:00 PM   #3
Registered: Sep 2004
Location: south texas
Distribution: fedora core 3,4; gentoo
Posts: 192

Rep: Reputation: 30
if its available in C, I'm sure it's available in C++. it's probably in <cstio>. although i know there are people out there who say it's a bad idea to use C code in C++. i'm not sure i necessarily understand why unless the C libraries do not have to be included by a Standard C++ compiler and you could have some protability issues. otherwise, if it's there, why not use it?


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
Any command-line tools which can edit EXIF image data? neocookie Linux - Software 1 01-27-2005 11:23 AM
writing gui wrappers for command line tools Genjix Programming 2 01-10-2005 09:25 AM
Command line tools to Find files with specific text naps Linux - Software 5 11-15-2004 04:46 AM
group command line tools m2azer Linux - General 4 10-31-2004 09:37 PM
how do I set a path for my java command line tools darkone66669 Linux - Newbie 1 04-19-2004 06:28 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:40 PM.

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