Home > Mobile >  macos C# : how can I start process with sudo prompt
macos C# : how can I start process with sudo prompt

Time:06-01

I have an application built in C# .dotnet 6 on macos.

I want the application to be able to seamlessly update itself.

It's downloads the latest pkg and my problem is how I run it.

I want to start this process using "sudo installer -pkg /tmp/mypackage.pkg -target /" but sudo ask for password on the standard input.

How can I start a process with escalated privileges where the user permissions are asked first through something like:

enter image description here

CodePudding user response:

You can use AppleScript to create a graphical authentication prompt:

#!/bin/sh
osascript -e "do shell script \"$*\" with administrator privileges"

Other methods: Is there any graphical "sudo" for Mac OS X?

CodePudding user response:

You could try the option -S of sudo for accepting the password from standard input. After use echo password and | to pass the password to the command:

echo myPassword | sudo -S installer -pkg /tmp/mypackage.pkg -target
  • Related