Qprocess:readAllStandardError is reading output of succesul gpg command
-
wrote on 13 Dec 2023, 08:54 last edited by Devesh Mishra
Hello
I am using gpg command to decrypt some files in my code using QProcess.
code is likeQProcess 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 passphraseand 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.encin 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
-
Hello
I am using gpg command to decrypt some files in my code using QProcess.
code is likeQProcess 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 passphraseand 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.encin 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
@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.
-
Hello
I am using gpg command to decrypt some files in my code using QProcess.
code is likeQProcess 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 passphraseand 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.encin 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
wrote on 13 Dec 2023, 09:04 last edited by JonB@Devesh-Mishra
You should not use emptiness or not of stderr to judge whether a program ran "successfully".
Use int QProcess::exitCode() const afterwaitForFinished()
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 useexit /b exit-code
from a.bat
file to get it to return a non-0 value to the caller.
1/3