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

Recommended Answers

All 3 Replies

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)

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

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.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.