QProcess::start() failed when application runs from sudo
Hi all,
I wrote a console application, which during work runs the external application. For this purpose I use QProcess.
When my application is being run by any user - everything works fine. But if my application runs from "sudo", then QProcess start failed with error QProcess::FailedToStart.
Does anyone know why this happens?
Thanks in advance.
Re: QProcess::start() failed when application runs from sudo
Have you checked that you can manually run your external application from the root account (or whatever account you run the main app in)? Possibly a difference in the environment: executable path, library path etc.
Re: QProcess::start() failed when application runs from sudo
Oh, it's very good idea.
I've tested it. When I run application from user or root it work nice. If I run it from "sudo" it faild with "command not found" error. But if I use "sudo -i" it work nice too.
So, I think it is not problem in QProcess.
Thanks for help.
Re: QProcess::start() failed when application runs from sudo
Quote:
Originally Posted by
alenyashka
When I run application from user or root it work nice. If I run it from "sudo" it faild with "command not found" error. But if I use "sudo -i" it work nice too.
From the sudo man page
Quote:
The -i (simulate initial login) option runs the shell specified in the passwd(5) entry of the target user as a login shell. This means that login-specific resource files such as .profile or .login will be read by the shell.
It works with "-i" and not without because the system default environment, specifically PATH, is being augmented by whatever is in the root user's login scripts (depends on the shell). When run without the "-i" you will get the system default environment which is usually very basic. Try something like:
Code:
$ sudo /usr/bin/env
$ sudo -i /usr/bin/env
to see the difference