why qprocess not execute mount command correctly ?
-
wrote on 9 Jan 2023, 12:01 last edited by Qt embedded developer 1 Sept 2023, 17:24
i have seen that when use mount /dev/sdb1 /mnt it not mount using qprocess ?
-
As always when you ask questions - please clarify, re-read your question and think if someone else could really understand what you're trying to ask.
My answer: No, noone understands your question...
-
wrote on 9 Jan 2023, 15:56 last edited by
The 'mount <dev> <mountpoint>' version is usually run with root permissions. Do you have them?
-
i have seen that when use mount /dev/sdb1 /mnt it not mount using qprocess ?
wrote on 9 Jan 2023, 15:58 last edited by JonB 1 Sept 2023, 15:59@Qt-embedded-developer
I would be surprised if that is really the case. Show yourQProcess
code. Check for any errors, e.g. permissions as @andr has remarked. -
The 'mount <dev> <mountpoint>' version is usually run with root permissions. Do you have them?
wrote on 9 Jan 2023, 17:21 last edited by Qt embedded developer 1 Sept 2023, 17:22 -
As always when you ask questions - please clarify, re-read your question and think if someone else could really understand what you're trying to ask.
My answer: No, noone understands your question...
wrote on 9 Jan 2023, 17:29 last edited byqprocess not execute below command correct way:
sudo mount /dev/sdb1 /mnt
what is right way to execute mount command using qprocess ?
i know how to use qprocess. so if possible let me know what argument argument i need to pass to make it correct ?
-
qprocess not execute below command correct way:
sudo mount /dev/sdb1 /mnt
what is right way to execute mount command using qprocess ?
i know how to use qprocess. so if possible let me know what argument argument i need to pass to make it correct ?
wrote on 9 Jan 2023, 17:37 last edited by JonB 1 Sept 2023, 17:37@Qt-embedded-developer said in why qprocess not execute mount command correctly ?:
i know how to use qprocess. so if possible let me know what argument argument i need to pass to make it correct ?
Then you won't mind showing your code for this, as requested? There is not somehow something "special", or a "special argument", because of using
QProcess
.
BTW this isn't going to work if yoursudo
requires a password. -
@Qt-embedded-developer said in why qprocess not execute mount command correctly ?:
i know how to use qprocess. so if possible let me know what argument argument i need to pass to make it correct ?
Then you won't mind showing your code for this, as requested? There is not somehow something "special", or a "special argument", because of using
QProcess
.
BTW this isn't going to work if yoursudo
requires a password.wrote on 9 Jan 2023, 18:00 last edited by Qt embedded developer 1 Sept 2023, 18:02QProcess OProcess; QString Command,sConnectedNodePath; Command = "sudo mount /dev/sdb1 /mnt "; OProcess.start(Command,QIODevice::ReadOnly); OProcess.waitForFinished(); QString sCommandOutput = OProcess.readAllStandardOutput(); QString StdError = OProcess.readAllStandardError(); if(StdError.isEmpty()) { qDebug() << "output : success"; } else{ qDebug() << "output : fail"; }
i got success output with not mounted directory at /mnt
-
Can you
qDebug() << sCommandOutput;
as well?
What happens if you enter the command on the command line with the user who is running the executable? Pls share the command line output as well. -
QProcess OProcess; QString Command,sConnectedNodePath; Command = "sudo mount /dev/sdb1 /mnt "; OProcess.start(Command,QIODevice::ReadOnly); OProcess.waitForFinished(); QString sCommandOutput = OProcess.readAllStandardOutput(); QString StdError = OProcess.readAllStandardError(); if(StdError.isEmpty()) { qDebug() << "output : success"; } else{ qDebug() << "output : fail"; }
i got success output with not mounted directory at /mnt
wrote on 9 Jan 2023, 19:26 last edited by JonB 1 Sept 2023, 19:45QProcess OProcess; Command = "sudo mount /dev/sdb1 /mnt "; OProcess.start(Command,QIODevice::ReadOnly);
Show what overload of
QProcess::start()
(and what version of Qt) you think accepts a single string ofsudo mount /dev/sdb1 /mnt
as its first/program
argument? I am not even sure which overload yours is using! Only QProcess::startCommand() accepts such a single-string command-line.i got success output
What "success"? I see only a check as to whether
StdError
is empty. Which I would expect to be the case. And as @Axel-Spoerl asked, showsCommandOutput
too, though I would expect that to be empty too. Plus please do confirm you have run this from the command line outside of Qt application, and its output.Attach slots in yours to signals
started
/stateChanged
/finished
/errorOccurred()
on yourOProcess
, and check return result ofwaitForFinished()
, if you want to check its behaviour. AlsoexitStatus()
&exitCode()
.Also confirm whether or not your
sudo
requires a password anyway?UPDATE
I see that at Qt 5.15 there was an obsoleted QProcess::start(const QString &command, QIODevice::OpenMode mode = ReadWrite), I guess that must be what you are using? You might still check the suggested slots, and showsCommandOutput
too. OK, please confirm again about yoursudo
password as well, and we will take it from there.... -
QProcess OProcess; QString Command,sConnectedNodePath; Command = "sudo mount /dev/sdb1 /mnt "; OProcess.start(Command,QIODevice::ReadOnly); OProcess.waitForFinished(); QString sCommandOutput = OProcess.readAllStandardOutput(); QString StdError = OProcess.readAllStandardError(); if(StdError.isEmpty()) { qDebug() << "output : success"; } else{ qDebug() << "output : fail"; }
i got success output with not mounted directory at /mnt
@Qt-embedded-developer said in why qprocess not execute mount command correctly ?:
Command = "sudo mount /dev/sdb1 /mnt ";
Please read the QProcess documentation: the parameters to the command are passed as a QStringList parameter to QProcess...
-
@Qt-embedded-developer said in why qprocess not execute mount command correctly ?:
Command = "sudo mount /dev/sdb1 /mnt ";
Please read the QProcess documentation: the parameters to the command are passed as a QStringList parameter to QProcess...
wrote on 10 Jan 2023, 12:55 last edited by@jsulm
Like I discovered, I think OP must be using the obsoleted QProcess::start(const QString &command, QIODevice::OpenMode mode = ReadWrite). Assuming that is so, there must be a deeper reason why it fails to work, yet to be discovered from OP's future responses....
1/12