在Mac OS上,我需要在Qt Desktop应用程序开始时卸载一堆驱动程序(kext)。我尝试使用QProcess,但kextunload需要具有管理员权限。有人知道解决方法吗?或者如何使用sudo启动QProcess?我需要这对最终用户来说很容易:只需在提示时输入管理员密码,应用程序就会完成其余的工作。
问题是苹果在设备上加载他们自己的驱动程序,我想使用特定的驱动程序(带有FT2Dxx驱动程序的FTDI232H)。
发布于 2018-06-04 05:14:48
我发现了一些似乎对我有用的东西:
QString password = "yourRootPassword"; //could be asked with QInputDialog::getText(...)
QString cmd = QString("sudo -S kextunload -b %1 > /dev/null").arg(driverName);
FILE *pipe = popen(cmd.toStdString().c_str(), "w");
if(pipe != nullptr)
{
fprintf(pipe, "%s\n", password.toStdString().c_str());
if (ferror(pipe))
{
qDebug() << "Failed to write to pipe";
}
else
{
qDebug() << "Written to pipe";
}
}
else
{
qDebug() << "Failed to open pipe";
}
qDebug() << "Pipe returned : " << pclose(pipe);
https://stackoverflow.com/questions/50657464
复制相似问题