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. Qprocess:readAllStandardError is reading output of succesul gpg command
Forum Updated to NodeBB v4.3 + New Features

Qprocess:readAllStandardError is reading output of succesul gpg command

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 259 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.
  • D Offline
    D Offline
    Devesh Mishra
    wrote on 13 Dec 2023, 08:54 last edited by Devesh Mishra
    #1

    Hello
    I am using gpg command to decrypt some files in my code using QProcess.
    code is like

    QProcess exec;
    QString cmdOutSucess;
    QString cmdOutError;
    
    cmdOutError.clear();
    cmdOutSucess.clear();
    
    exec.start(cmd);
    exec.waitForFinished(-1);
    
    cmdOutError = exec.readAllStandardError();
    cmdOutSucess = exec.readAllStandardOutput();
    
    qDebug()<<cmd;
    qDebug()<<cmdOutError;
    qDebug()<<cmdOutSucess;
    
    if(cmdOutError.isEmpty())
    {
      result = true;
    }
    else
    {
          cmdOutError = "MetaFiles generation Failed";
    }
    

    Code is running as expected, file is successfully decrypted.
    but after decryption , i am checking for any error.
    for this purpose , i use to read the std err/out data using "readAllStandardError();" and "readAllStandardOutput()".

    in this case however file is successfully decrypted ,cmdOutError contains following string
    gpg: AES encrypted data
    gpg: encrypted with 1 passphrase

    and because of this my validation check cmdOutError.isEmpty() failed.

    I suppose that this string shall come into cmdOutSucess and cmdOutError will be empty as no error occured.

    I do not know what i am doing wrong here.
    can we get the return value of gpg command because in its description , it is wrriten that programs return 0 when success but how to get that value.

    for encryption command is :
    gpg --batch --output data4.enc --passphrase 1234 -c test.txt
    for decryption command is
    gpg --batch --output test.txt --passphrase 1234 --decrypt data4.enc

    in code , i need to check whether command is executed succesfully or not.

    i am using qt and linux 8.x

    please suggest the suitable way for performing this

    J J 2 Replies Last reply 13 Dec 2023, 08:58
    0
    • D Devesh Mishra
      13 Dec 2023, 08:54

      Hello
      I am using gpg command to decrypt some files in my code using QProcess.
      code is like

      QProcess exec;
      QString cmdOutSucess;
      QString cmdOutError;
      
      cmdOutError.clear();
      cmdOutSucess.clear();
      
      exec.start(cmd);
      exec.waitForFinished(-1);
      
      cmdOutError = exec.readAllStandardError();
      cmdOutSucess = exec.readAllStandardOutput();
      
      qDebug()<<cmd;
      qDebug()<<cmdOutError;
      qDebug()<<cmdOutSucess;
      
      if(cmdOutError.isEmpty())
      {
        result = true;
      }
      else
      {
            cmdOutError = "MetaFiles generation Failed";
      }
      

      Code is running as expected, file is successfully decrypted.
      but after decryption , i am checking for any error.
      for this purpose , i use to read the std err/out data using "readAllStandardError();" and "readAllStandardOutput()".

      in this case however file is successfully decrypted ,cmdOutError contains following string
      gpg: AES encrypted data
      gpg: encrypted with 1 passphrase

      and because of this my validation check cmdOutError.isEmpty() failed.

      I suppose that this string shall come into cmdOutSucess and cmdOutError will be empty as no error occured.

      I do not know what i am doing wrong here.
      can we get the return value of gpg command because in its description , it is wrriten that programs return 0 when success but how to get that value.

      for encryption command is :
      gpg --batch --output data4.enc --passphrase 1234 -c test.txt
      for decryption command is
      gpg --batch --output test.txt --passphrase 1234 --decrypt data4.enc

      in code , i need to check whether command is executed succesfully or not.

      i am using qt and linux 8.x

      please suggest the suitable way for performing this

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 13 Dec 2023, 08:58 last edited by jsulm
      #2

      @Devesh-Mishra It is up to the application what it writes to stdout or stderr. Looks like gpg writes some output to stderr even if this is not error. If you want to check whether the app ran successfully or not you should check its return value, not stderr.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • D Devesh Mishra
        13 Dec 2023, 08:54

        Hello
        I am using gpg command to decrypt some files in my code using QProcess.
        code is like

        QProcess exec;
        QString cmdOutSucess;
        QString cmdOutError;
        
        cmdOutError.clear();
        cmdOutSucess.clear();
        
        exec.start(cmd);
        exec.waitForFinished(-1);
        
        cmdOutError = exec.readAllStandardError();
        cmdOutSucess = exec.readAllStandardOutput();
        
        qDebug()<<cmd;
        qDebug()<<cmdOutError;
        qDebug()<<cmdOutSucess;
        
        if(cmdOutError.isEmpty())
        {
          result = true;
        }
        else
        {
              cmdOutError = "MetaFiles generation Failed";
        }
        

        Code is running as expected, file is successfully decrypted.
        but after decryption , i am checking for any error.
        for this purpose , i use to read the std err/out data using "readAllStandardError();" and "readAllStandardOutput()".

        in this case however file is successfully decrypted ,cmdOutError contains following string
        gpg: AES encrypted data
        gpg: encrypted with 1 passphrase

        and because of this my validation check cmdOutError.isEmpty() failed.

        I suppose that this string shall come into cmdOutSucess and cmdOutError will be empty as no error occured.

        I do not know what i am doing wrong here.
        can we get the return value of gpg command because in its description , it is wrriten that programs return 0 when success but how to get that value.

        for encryption command is :
        gpg --batch --output data4.enc --passphrase 1234 -c test.txt
        for decryption command is
        gpg --batch --output test.txt --passphrase 1234 --decrypt data4.enc

        in code , i need to check whether command is executed succesfully or not.

        i am using qt and linux 8.x

        please suggest the suitable way for performing this

        J Offline
        J Offline
        JonB
        wrote on 13 Dec 2023, 09:04 last edited by JonB
        #3

        @Devesh-Mishra
        You should not use emptiness or not of stderr to judge whether a program ran "successfully".
        Use int QProcess::exitCode() const after waitForFinished() to access exit/return code of program. However, you show a batch file which executes various sub-commands. As written I doubt you will get an non-zero exit code from this if one iteration returns that. You may have to rewrite you batch file to achieve that, and IIRC you need to use exit /b exit-code from a .bat file to get it to return a non-0 value to the caller.

        1 Reply Last reply
        2

        1/3

        13 Dec 2023, 08:54

        • Login

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