Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Sudo command (linux) through a QThread
Forum Updated to NodeBB v4.3 + New Features

Sudo command (linux) through a QThread

Scheduled Pinned Locked Moved General and Desktop
11 Posts 2 Posters 3.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pedro79
    wrote on last edited by
    #2

    QProcess is a QIODevice so just write the 'y' and the password after launching the process into the device.

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kamhagh
      wrote on last edited by
      #3

      Thanks ! I don't know ehat QIO is but im googling, i can guess what i should do now!!! Ty

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kamhagh
        wrote on last edited by
        #4

        [quote author="pedro79" date="1405877522"]QProcess is a QIODevice so just write the 'y' and the password after launching the process into the device.[/quote]

        [quote author="pedro79" date="1405877522"]QProcess is a QIODevice so just write the 'y' and the password after launching the process into the device.[/quote]

        i tried this, @ QProcess p;
        QString command = "sudo apt-get install ";
        command.append(pack);
        p.start(command);
        p.write(pass);
        p.write("y");@

        can you tell me what i'm doing wrong :(? sorry i can't find it on net!

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kamhagh
          wrote on last edited by
          #5

          i give up, can you tell how to do it?:( in code!!!

          1 Reply Last reply
          0
          • P Offline
            P Offline
            pedro79
            wrote on last edited by
            #6

            first open to read.
            then wait until you can write:
            waitForReadyRead(int msecs)

            1 Reply Last reply
            0
            • K Offline
              K Offline
              kamhagh
              wrote on last edited by
              #7

              [quote author="pedro79" date="1405887248"]first open to read.
              then wait until you can write:
              waitForReadyRead(int msecs)
              [/quote]

              :o good, i will try that tomorrow, i currently wrote a non GUI app to download my package over night :D hope it works!!
              EDIT: 6Am, and im still awake, let me try to see if it works! my terminal programm worked btw, its upgrading ubuntu and downloading steam !!!

              Edit2: im getting nowhere, i dont understand what i should do:( :(

              as i know
              i first make a process , then i make a stringlist for arguments, my arguments are apt-get and install and lets say wine, than i start it with "sudo" as prog and args as arguments, tthen i wait for ready ready ! and i write to it, it still gives same result, im so confused !! read like 100 pages of stuff still i dont get it! im disapointed of myself:(

              this is what im trying right now:

              @ QProcess process;
              process.open(QIODevice::ReadWrite);
              process.waitForReadyRead();
              QStringList args;
              args << "apt-get" << "install" << "wine";
              process.start("sudo",args);
              process.waitForReadyRead();
              process.write("mepass");
              process.waitForFinished(-1);
              qDebug() << process.readAll();
              qDebug() << process.errorString();@

              it asks for password!

              edit3:

              @ QProcess process;
              process.setProgram("/bin/sh");
              process.startDetached("/bin/sh", QStringList()<< "-c"
              << "echo y | sudo -S apt-get install gimp");
              process.waitForFinished();@

              this works if i open app with sudo !

              if i put my pass instead of y it works but requires users input for y! and write("y") doesn't work, i tried putting wait for !

              1 Reply Last reply
              0
              • P Offline
                P Offline
                pedro79
                wrote on last edited by
                #8

                start the process "sudo apt-get..."

                then open it for writing

                write your password (did you really post your password here in the forum: kamranwill ?)

                waitforwritten

                write "y"

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  kamhagh
                  wrote on last edited by
                  #9

                  Plz remove my pass(edit) ! Im such an Idiot

                  When you stay awake for 24H weird stuff happen !!

                  I knew its gonna happen! I checked 2x times but still i was sure !!:D

                  I changed it to something but guess i control-z before posting ;(

                  Im gonna try that thanks!!!! I will also make sure im opening right!!!

                  1 Reply Last reply
                  0
                  • K Offline
                    K Offline
                    kamhagh
                    wrote on last edited by
                    #10

                    [quote author="pedro79" date="1405935500"]# start the process "sudo apt-get..."

                    then open it for writing

                    write your password (did you really post your password here in the forum: kamranwill ?)

                    waitforwritten

                    write "y"[/quote]

                    its not like im lazy or anything, i just can't figure out!

                    i was always bad at I/O !!!!

                    anyway:

                    i first make process:
                    @QProcess proc;@

                    then i start the process with sudo apt-get upgrade:
                    @proc.start("sudo", QStringList() << "apt-get" << "upgrade");@

                    then i wait for it to do it because i tried without it and it says process already running:
                    @
                    proc.waitForReadyRead();@

                    then i open it as write:
                    @proc.open(QIODevice::WriteOnly);@

                    than i write my password:
                    @proc.write("not this time :D");@
                    and i wait for bytes to be writen:

                    @ proc.waitForBytesWritten();
                    proc.waitForFinished();@

                    also i dont need the "y" for upgrade so i dont inlcude it, it doesn't do anything!

                    when i run my app from terminal it still wants me to enter password !

                    from what you told me it should work!!! can you tell me where im doing wrong!?

                    edit:
                    i had to reinstall linux, and i had qt setup on my second hdd, my second hdd doens't work, i dont know why anyway i lost ssetup:( i have to download it again tonight, than i can start to see if i can find out myself,

                    1 Reply Last reply
                    0
                    • K Offline
                      K Offline
                      kamhagh
                      wrote on last edited by
                      #11

                      I just give up. Also my pc is dead ;(

                      I have another problem now!

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved