PDA

View Full Version : i cant able to mount my pendrive using qprocess



iswaryasenthilkumar
16th September 2015, 13:10
i created one script file (script.sh) inside that file i have written the command to mount


sudo mount -o umask=0 /dev/sdb1 /media/usb

i called this file using Qprocess,the result its mounted,


int Widget::process()
{
QProcess transcodescript;
QStringList arguments;
QString program ="/bin/sh";
arguments << SCRIPTFILEPATH;
transcodescript.start(program, arguments);
status=transcodescript.waitForFinished(-1);
if(!status)
{
qDebug()<<"failed to mount";
}
return SUCCESS;
}

i dont get any error for this above command,but when i use that command in terminal its get mounting,,i know am doing some mistakes please can any one give me solution for this.
Thanks in Advance:o

anda_skoa
16th September 2015, 13:36
In the case of manual invocation you might have used sudo before and entered the password there so you were already authenticated when sudo of the script ran.

You could try using the -S option to make sudo ask for the password on stderr and read it from stdin, or provide a program to --askpass or configure one (all documented in the sudo man page).

Of course using sudo assumes that the user running you program has the permission to use sudo to gain elevated privilegdes.
But then again, even having code to mount suggests that you are not targetting a desktop system but more likely some custom setup and can configure the system appropriately.

Cheer,
_

ChrisW67
16th September 2015, 21:09
If SCRIPTFILEPATH is a relative path then the whole thing could be failing* because the current working directory is not where you think it is.

*your original post indicates that everything is working but I assume it is not.

iswaryasenthilkumar
18th September 2015, 07:52
i checked in my pc ubuntu Linux (Filesystem -> /dev/sdb1 )->this will be created when i insert my pendrive
so i used command

sudo mount /dev/sdb1 /media/usb

sudo mount -o umask=0 /dev/sdb1 /media/usb
i checked both command in my terminal both command are mounted my pendrive,,but when i used this command by using Qprocess command not working and my pendrive not get mounted:(
my SCRIPTFILEPATH in home directory

If SCRIPTFILEPATH is a relative path then the whole thing could be failing* because the current working directory is not where you think it is.

*your original post indicates that everything is working but I assume it is not.

Added after 1 18 minutes:

i have one more doubt in this when i use sudo in terminal it will ask password to execute the command like wise i assigned command in my script
sudo mount-o umask=0 /dev/sdb1 /media/usb,,i need to pass the password in Qprocess how to assign my password using Qprocess,can any one help me o rectify this problem

anda_skoa
18th September 2015, 08:37
i need to pass the password in Qprocess how to assign my password using Qprocess,can any one help me o rectify this problem
You give no indication which of the suggested options you have already tried.

Cheers,
_

iswaryasenthilkumar
18th September 2015, 10:13
i rechanged my command in script

sudo mount -o umask=0 /dev/sdb1 /media/usb | grep welcome@1
welcome@1 is password for sudo command
i tries this in terminal its working but its not working through app:(

You give no indication which of the suggested options you have already tried.

Cheers,
_

anda_skoa
18th September 2015, 10:43
i rechanged my command in script

sudo mount -o umask=0 /dev/sdb1 /media/usb | grep welcome@1
welcome@1 is password for sudo command

That might very well be, but here you are grepping (filtering) the output of the command for the password.

Instead of doing things that do not even have the potential of having a positive impact, why don't you try some of the suggestions that might?

Cheers,
_

iswaryasenthilkumar
18th September 2015, 11:43
i used this command
echo welcome@1 | sudo -S mount -o umask=0 /dev/sdb1 /media/usb its worked both in terminal and Qprocess
Thank you anda_skoa
That might very well be, but here you are grepping (filtering) the output of the command for the password.

Instead of doing things that do not even have the potential of having a positive impact, why don't you try some of the suggestions that might?

Cheers,
_