命令行(工作正常(
$ sudo chPermissions.sh
尝试在Qt程序中使用QProcess来完成此操作,并尝试了以下操作,但没有成功
代码:
QString program = "/bin/sh /usr/bin/chPermissions.sh";
m_process->start(program);
m_process->waitForFinished();
qDebug() << m_process->exitCode();
结果:0(脚本运行,但没有sudo权限&不起作用!(
代码:
QString program = "sudo /bin/sh /usr/bin/chPermissions.sh";
m_process->start(program);
m_process->waitForFinished();
qDebug() << m_process->exitCode();
结果:1
代码:
QString program = "/usr/bin/sudo /bin/sh /usr/bin/chPermissions.sh";
m_process->start(program);
m_process->waitForFinished();
qDebug() << m_process->exitCode();
结果:1
代码:
QString program = "/bin/sh";
QStringList arguments;
arguments << "/usr/bin/chPermissions.sh";
m_process->start(program, arguments);
m_process->waitForFinished();
qDebug() << m_process->exitCode();
结果:0(脚本运行!没有sudo权限(
代码:
QString program = "/bin/sh";
QStringList arguments;
arguments << sudo << "/usr/bin/chPermissions.sh";
m_process->start(program, arguments);
m_process->waitForFinished();
qDebug() << m_process->exitCode();
结果:127(未找到命令(
代码:
QString program = "/bin/sh";
QStringList arguments;
arguments << /usr/bin/sudo << "/usr/bin/chPermissions.sh";
m_process->start(program, arguments);
m_process->waitForFinished();
qDebug() << m_process->exitCode();
结果:2(滥用外壳内置(
代码:
QString program = "/bin/bash";
QStringList arguments;
arguments << "-c" << ""/usr/bin/sudo /usr/bin/chPermissions.sh"";
m_process->start(program, arguments);
m_process->waitForFinished();
qDebug() << m_process->exitCode();
结果:127
代码:
QString shellCommandLine = "/usr/bin/chPermissions.sh";
QStringList arguments;
arguments << "-c" << shellCommandLine;
m_process->start("/bin/sh", arguments);
m_process->waitForFinished();
qDebug() << "Exit Code: " << m_process->exitCode();
结果:0(脚本运行!(
代码:
QString shellCommandLine = "sudo /usr/bin/chPermissions.sh";
QStringList arguments;
arguments << "-c" << shellCommandLine;
m_process->start("/bin/sh", arguments);
m_process->waitForFinished();
qDebug() << "Exit Code: " << m_process->exitCode();
结果:1
代码:
QString shellCommandLine = "/usr/bin/sudo /usr/bin/chPermissions.sh";
QStringList arguments;
arguments << "-c" << shellCommandLine;
m_process->start("/bin/sh", arguments);
m_process->waitForFinished();
qDebug() << "Exit Code: " << m_process->exitCode();
结果:1
代码:
QString shellCommandLine = "/usr/bin/chPermissions.sh";
QStringList arguments;
arguments << "-c" << shellCommandLine;
m_process->start("/bin/sh", arguments);
m_process->waitForFinished();
qDebug() << "Exit Code: " << m_process->exitCode();
结果:0(脚本在没有sudo权限的情况下运行(
有谁能让我知道如何做到这一点的秘密吗?(或者如果不可能的话,让我摆脱痛苦(
TIA-
Andy
未按此方式解决。
我通过绕过了这个
- 使用实际运行脚本的选项之一(没有su权限(,以及
- 在sudoers中授予用户在没有密码提示的情况下运行脚本中的命令的权限
希望这是有道理的。
不快乐,但它有效。