0

Hello

I want to run a command as sudo (to be especific open a file) but I dont want to run the entire program as sudo obviously. How do i do a fopen with sudo previlges? I dont mind hardcoding the password (eg, so it wont ask me for my password) as this is for me and only I will use it.

Thank you

3
Contributors
3
Replies
5
Views
5 Years
Discussion Span
Last Post by L7Sqr
0

I don't know if this will work. But if you elevate the program like this:

system ("sudo bash-something" + somestring);  //results in the command 'sudo bash -something:somestring ' being called

That should give you should give you sudo ( think ).

system() allows you to run a command on the system (only works on linux afaik)

0

But where is my password? When I call sudo (or su in my case) it has to always ask me for my password.

0

You have a couple of options.

  • Since this is 'just for you' then just run the entire program as root
  • Run the program as root, but drop priveleges once you open the file
  • Use a combination of the two above and run as root, fork a child to do root-related things and have the parent drop priveleges and do non-root things.
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.