Results 1 to 2 of 2

Thread: Executing linux command as root

  1. #1
    Join Date
    May 2008
    Location
    Rijeka, Croatia
    Posts
    85
    Thanks
    10
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Executing linux command as root

    I want to execute a linux command as a root user, from my C++/Qt code. Ultimately a a dialog requesting root pass should be implemented, but for no I can hard-code root password.

    This is what I done so far:
    Qt Code:
    1. p.start( "dmidecode" );
    2. p.waitForFinished(-1);
    3.  
    4. QString p_stdout = p.readAllStandardOutput();
    5. QString p_stderr = p.readAllStandardError();
    To copy to clipboard, switch view to plain text mode 
    And it is working for commands that do not request root privileges. But I want to implement commands like "zypper up" or "dmidecode" which I can't execute without a root password.

    Probably something can be done with void QProcess::setEnvironment ( const QStringList & environment )?

    Thanks

    NOTE: Also posted on stackoverflow

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Executing linux command as root

    It's best if you use PolicyKit but you can also call kdesu or alike if it fits your purpose.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Open/Executing Files on Linux
    By MBex in forum Qt Programming
    Replies: 5
    Last Post: 3rd June 2011, 00:15
  2. Replies: 7
    Last Post: 15th November 2010, 09:00
  3. executing a audio player code on Embedded linux
    By sureshlohith in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 21st April 2010, 05:17
  4. Running an application with root privileges at Linux
    By prykHetQuo in forum Qt Programming
    Replies: 5
    Last Post: 25th January 2009, 12:35
  5. Linux/Bash: Run a command as another user
    By sunil.thaha in forum General Discussion
    Replies: 1
    Last Post: 5th December 2006, 09:49

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.