G
G
gkozyrev2019-11-14 16:43:35
go
gkozyrev, 2019-11-14 16:43:35

Root for Golang - programs?

Hello everyone)
I am writing a mini-application in Go for myself.
For the GUI, I use the Fyne framework.
The essence of the question: is it possible to make my application perform actions that require superuser rights (for example, edit files like hosts)?
Well, I would like it to pop up a window like this:
auth_request-1024x635.png
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
uvelichitel, 2019-11-14
@uvelichitel

To execute a system command in Go use os/exec
/usr/bin/osascript to pop up a window in osx
Try something like

package main
import (
  "os/exec"
  ...
)

func main(){
...
//Чтобы получить приглашение в консоли
  cmd := exec.Command("sudo", "su")  
  err := cmd.Run()
  if err != nil {
    fmt.Printf("%s", err)
  }
...
//Или чтобы выпало окошко
  out, err := exec.Command("osascript", "-e", "do shell script /path/to/myscript with administrator privileges").Output()
  if err != nil {
    fmt.Printf("%s", err)
  }
...
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question