3

Most of the other questions about this seem to be C related. I am using Free Pascal and the Lazarus IDE, version 2.4.0 and 0.9.30 respectively.

I am creating a GUI that calls and passes arguments to a Linux command. I don't want my users to have to run the whole GUI using sudo\root, but rather be prompted for the password at the appropriate time.

I am using TProcess to call the Linux commands and pass and read values. I can't work out, though, how to pass the sudo password to the command from my own program?

To give an example, take the following normal command line:

dd if=/dev/hda1 of=~/image.dd
Enter sudo password:

My program is calling dd, passing it the if and of values from a GUI interface - it then needs to gather and pass the sudo password to dd.

Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
Gizmo_the_Great
  • 979
  • 13
  • 28
  • Can anyone tell or show me an example of how it's been done using another language, then, and perhaps from that I can work out how to apply it to Free Pascal. ?? Thanks Ted – Gizmo_the_Great Sep 02 '11 at 10:05
  • 2
    What about using TProcess to run gksudo instead of running the command directly? – Dmitri Sep 17 '11 at 22:18

2 Answers2

3

A little bit old, but - use pkexec in front of your command, like: pkexec ls /root

You will have each time the GUI info for entering root password. Tested on LinuxMint

Andro Selva
  • 53,910
  • 52
  • 193
  • 240
jack_
  • 31
  • 1
2

On the premise that you're already using TProcess, instead of issuing the command line call directly to dd you can use one of the following established methods of invoking su/sudo:

Gustavo Carreno
  • 9,499
  • 13
  • 45
  • 76