GO filevault status, os/exec or plist

104 views Asked by At

I need to write a code in GO that checks the status of fileVault.
Since I could not find the plist file that contains that information I turned to check it via the terminal using os/exec package.

I know that from the terminal I can execute the command " fdesetup status" to get the status, so I've tried the following code:

    cmd := exec.Command( "fdesetup status")
    var out bytes.Buffer
    var stderr bytes.Buffer
    cmd.Stdout = &out
    cmd.Stderr = &stderr
    err := cmd.Run()
    if err != nil {
        fmt.Println(fmt.Sprint(err) + ": " + stderr.String())
        return
    }
    fmt.Println("Result: " + out.String())

Which resulted in the error: "exec: "fdesetup status": executable file not found in $PATH: "

I've tried to change the exec command to: "date" instead of "fdesetup status" which worked fine, so it seems there is no need to add some kind of invocation to the terminal.

To get around it I've tried to use exec.Command("echo", "fdesetup status")

and exec.Command("echo", "$(fdesetup status)") both worked in the terminal, but did not provide the information when executed via GO.

I would appreciate any help figuring out how to gain fileVault status information via GO.

0

There are 0 answers