There is no standard package manager for Linux, so dpkg is definitely the wrong answer.
For security and correctness reasons, it is probably unwise to rely on the user's PATH to find the executable. Therefore, you should probably already use the full path (e.g. /usr/bin/gifsicle ) in your call to system .
If yes, then a simple answer to your question:
if (access("/usr/bin/gifsicle", X_OK) == 0) { system("/usr/bin/gifsicle -my -args"); } else if (errno == EACCESS) { /* gifsicle not found */ } else { /* access() failed! Operating system is broken or Windows (or both) */ }
(Bonus points if you enter /usr/bin/gifsicle into a variable)
The harder - but perhaps more "correct" - the answer is to avoid the system and make fork + execl yourself by checking execl to see if it leads to ENOENT or the like. However, announcing the abandonment of the parent process can be annoying.
source share