command line (works fine)
$ sudo chPermissions.sh
trying to do this from within a Qt program, using QProcess and have tried the following without success
code:
QString program = "/bin/sh /usr/bin/chPermissions.sh";
m_process->start(program);
m_process->waitForFinished();
qDebug() << m_process->exitCode();
result: 0 (the script ran but without sudo rights & didn't work!)
code:
QString program = "sudo /bin/sh /usr/bin/chPermissions.sh";
m_process->start(program);
m_process->waitForFinished();
qDebug() << m_process->exitCode();
result: 1
code:
QString program = "/usr/bin/sudo /bin/sh /usr/bin/chPermissions.sh";
m_process->start(program);
m_process->waitForFinished();
qDebug() << m_process->exitCode();
result: 1
code:
QString program = "/bin/sh";
QStringList arguments;
arguments << "/usr/bin/chPermissions.sh";
m_process->start(program, arguments);
m_process->waitForFinished();
qDebug() << m_process->exitCode();
result: 0 (the script ran! no sudo rights)
code:
QString program = "/bin/sh";
QStringList arguments;
arguments << sudo << "/usr/bin/chPermissions.sh";
m_process->start(program, arguments);
m_process->waitForFinished();
qDebug() << m_process->exitCode();
result: 127 (command not found)
code:
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();
result: 2 (Misuse of shell builtins)
code:
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();
result: 127
code:
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();
result: 0 (the script ran!)
code:
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();
result: 1
code:
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();
result: 1
code:
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();
result: 0 (script ran without sudo rights)
Anyone able to let me know the secret of how to do this? (or put me out of my misery if it's not possible)
TIA
Andy