Results 1 to 4 of 4

Thread: QProcess::start() failed when application runs from sudo

  1. #1
    Join Date
    Jun 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default 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.

  3. #3
    Join Date
    Jun 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QProcess::start() failed when application runs from sudo

    Quote Originally Posted by alenyashka View Post
    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
    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:
    Qt Code:
    1. $ sudo /usr/bin/env
    2. $ sudo -i /usr/bin/env
    To copy to clipboard, switch view to plain text mode 
    to see the difference

Similar Threads

  1. Replies: 5
    Last Post: 3rd February 2010, 23:50
  2. QProcess to Start App
    By ManuMies in forum Qt Programming
    Replies: 2
    Last Post: 29th May 2009, 11:58
  3. The Gdb process failed to start.
    By been_1990 in forum Qt Tools
    Replies: 3
    Last Post: 29th April 2009, 17:29
  4. Replies: 2
    Last Post: 20th November 2007, 20:00
  5. QProcess start automaticaly needed application
    By raphaelf in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2006, 14:11

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.