PDA

View Full Version : QProcess unable to start shell commands linux



milli
13th March 2011, 20:45
I would like to execute shell commands using QProcess,i have searched forum and read documentation but i can't solve my problem.
For example,

cmdline="/bin/bash";
arguments << "-c" << "sudo apt-get install";
process->start(cmdline,arguments,QIODevice::ReadWrite);
The result of above program is:
sudo: no tty present and no askpass program specified

If the arguments are:
arguments << "-c" << "ls -l";
then the function is executed correctly.

i have edited sudoers file using visudo in order not to ask password for a specific user.
Thanks!

wysota
14th March 2011, 10:20
The problem is obviously with sudo and not with Qt.

milli
14th March 2011, 20:55
As wysota wrote, the problem was with sudo. (The command was not executing due to editting sudoers file).
If someone else has similar problem the following code works:
QString apath,program;
QStringList args;
apath=QDir("/bin/bash").absolutePath());
program="gksudo";
args << "apt-get install";
process->start(program,args);