Results 1 to 5 of 5

Thread: QProcess::execute() within service not using inherited PATH

  1. #1
    Join Date
    Nov 2008
    Posts
    183
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QProcess::execute() within service not using inherited PATH

    It's late and I could just be thick.

    32-bit Ubuntu 12.4.5
    latest Qt 5.x

    Have a service with a .conf file. It launches a shell script which runs a watchdog program. The watchdog program does many setup verification things then it does a Qt execute() of another shell file. This shell file runs the actual application.

    Here is the interesting thing. The shell script makes calls to logger which show it really does inherit the PATH value from the parent process. It doesn't actually use it though.

    If I run the program with just programName it dies with an exit code 2, program not found. If I hardcode the full path of /home/userName/bin/programName it dies with an exit code of 134.

    I can use a sudo command from my own directory (which, should, in theory, be the same the service conf start on login-session-start) everything works. It is like execute() doesn't pass a complete environment in this instance.

    The .conf for the service does chdir to the actual directory for the program.

    Anyone else encounter this?

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QProcess::execute() within service not using inherited PATH

    Look at QProcessEnvironment. You can modify the path, then set your QProcess to use the new environmental variables using QProcess::setEnvironment.

  3. The following user says thank you to jefftee for this useful post:

    RolandHughes (15th June 2015)

  4. #3
    Join Date
    Nov 2008
    Posts
    183
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QProcess::execute() within service not using inherited PATH

    Quote Originally Posted by jefftee View Post
    Look at QProcessEnvironment. You can modify the path, then set your QProcess to use the new environmental variables using QProcess::setEnvironment.
    Thank you for the attempt. We are going to have to bail on creating this as a service. Going back to the old fashioned never ending automatically restarting cron job approach. First level works perfectly, but second does not. I assume there is some undocumented (or sparsely documented) "feature" with service which forces forks instead of letting the executing watchdog create a totally different process which it monitors.

  5. #4
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QProcess::execute() within service not using inherited PATH

    Not sure why you need to bail on your attempt to create a service. Do you have other issues/challenges besides the PATH environmental variable?

  6. #5
    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::execute() within service not using inherited PATH

    Here is the interesting thing. The shell script makes calls to logger which show it really does inherit the PATH value from the parent process.
    If I run the program with just programName it dies with an exit code 2, program not found. If I hardcode the full path of /home/userName/bin/programName it dies with an exit code of 134.
    So you have demonstrated:
    1. QProcess started the shell script with the expected PATH
    2. The shell script with the expected PATH fails to launch your program because the program is not on the PATH or for some other reason.
    3. When you eliminate the PATH search the shell script executes your program which promptly fails for some other reason.

    Point 2 and 3 demonstrate that the problem is not related to Qt. The exit codes returned by QProcess::execute() are those of the shell running your shell script and only meaningful in that context.

Similar Threads

  1. QProcess does not work in service
    By yasjera in forum Qt Programming
    Replies: 5
    Last Post: 6th June 2014, 11:03
  2. Execute system command from QProcess
    By graciano in forum General Programming
    Replies: 6
    Last Post: 20th February 2014, 10:05
  3. QProcess does not execute Automator app in OSX 10.6
    By Markus in forum Qt Programming
    Replies: 1
    Last Post: 19th April 2010, 04:12
  4. How to use the QProcess to execute the Browser ?
    By eric0214 in forum Qt for Embedded and Mobile
    Replies: 7
    Last Post: 21st December 2009, 10:06
  5. How to use the QProcess to execute the Browser ?
    By eric0214 in forum Qt Programming
    Replies: 2
    Last Post: 17th November 2009, 06:18

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.