What's the best way to check for external applications?
It is inefficient (requires forking and exec'ing / bin / sh). There must be a better way! But as a general approach ... There is always system ().
(Don't forget to use WEXITSTATUS ()! Don't forget to make your programs run smooth!)
#define SHOW(X) cout << # X " = " << (X) << endl
int main()
{
int status;
SHOW( status = system( "which grep > /dev/null 2>&1" ) );
SHOW( WEXITSTATUS(status) );
SHOW( status = system( "which no_matching_file > /dev/null 2>&1" ) );
SHOW( WEXITSTATUS(status) );
}
There is also popen (), which can be useful for capturing the output from programs to check version numbers, libraries, or whatever.
If you need bi-directional (read and write) access to a subprocess, it is best to use pipe (), fork (), exec (), close (), and dup2 ().
source to share
I don't know how to do this for Linux in general, as each distribution can have its own package manager. But, assuming you want to support the most popular distributions, you can query their package manager for the installed software (I would suggest supporting apt-get, rpm, and yum as a starting point) and parse the output to find packages you recognize. Each manager has a way to list installed packages, my suggestion as a start:
apt-get --no-act check
rpm -qa
yum list installed
source to share
Another possibility is to present all the features to the user and prompt them to install additional features if they try to use them (for example, see http://0install.net ).
source to share