LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   C++ Interfacing with command line tools (https://www.linuxquestions.org/questions/programming-9/c-interfacing-with-command-line-tools-313222/)

khermans 04-14-2005 01:08 PM

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

keefaz 04-14-2005 01:43 PM

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)

sirclif 04-14-2005 03:00 PM

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?


All times are GMT -5. The time now is 01:59 AM.