我有一个应用程序有可选的附加功能,具体取决于用户是否安装了该软件。
在 Linux 上,确定是否安装了 python 和 PyUsb 之类的最佳方法是什么?
如果有帮助,我正在开发 C++ Qt 应用程序。
最佳答案
这是低效的(需要 fork 和执行 /bin/sh)。一定有更好的方法!但作为一种通用方法...总是有 system()。
(记得使用WEXITSTATUS()!注意让程序不间断!)
#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) );
}
还有 popen(),它可用于从程序中获取输出以验证版本号、库或诸如此类的东西。
如果您需要对子进程进行双向(读&写)访问,最好使用pipe()、fork()、exec() , close(), & dup2()。
关于c++ - 检查外部应用程序是否可用的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/406966/