github.com/Schaudge/grailbase@v0.0.0-20240223061707-44c758a471c0/web/webutil/browser_windows.go (about)

     1  // Copyright 2018 GRAIL, Inc. All rights reserved.
     2  // Use of this source code is governed by the Apache-2.0
     3  // license that can be found in the LICENSE file.
     4  
     5  // +build windows
     6  
     7  package webutil
     8  
     9  import (
    10  	"fmt"
    11  	"os/exec"
    12  	"runtime"
    13  	"syscall"
    14  )
    15  
    16  // StartBrowser tries to open the URL in a browser and reports whether it
    17  // succeeds.
    18  func StartBrowser(url string) bool {
    19  	cmd := exec.Command("cmd")
    20  	if runtime.GOOS == "windows" {
    21  		cmd.SysProcAttr = &syscall.SysProcAttr{
    22  			CmdLine: fmt.Sprintf(`cmd /c start "" "%s"`, url),
    23  		}
    24  	}
    25  	return cmd.Start() == nil
    26  }