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.
|
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. :) |
You can use either system or execvp (et. al.)
ta0kira |
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.
|
Quote:
|
All times are GMT -5. The time now is 11:41 PM. |