开发者

How to pass sudo\root password to a Linux command using Free Pascal

Most of the other questions about this seem to be C related. I am using Free Pascal and the Lazarus IDE, version开发者_Go百科 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.


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


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:

  • gksudo (Ubuntu natty man page)
  • kdesudo (Ubuntu natty man page)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜