当前位置: 首页>>代码示例>>Golang>>正文


Golang exec.LookPath函数代码示例

本文整理汇总了Golang中os/exec.LookPath函数的典型用法代码示例。如果您正苦于以下问题:Golang LookPath函数的具体用法?Golang LookPath怎么用?Golang LookPath使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了LookPath函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: getGlobalNodePath

func getGlobalNodePath() string {
	var path string

	if env, ok := IsSessionEnv("", false); ok {
		if reg, err := regexp.Compile(`\\([0]|[1-9]\d?)(\.([0]|[1-9]\d?)){2}(-x(86|64))?\\$`); err == nil {
			ver := reg.FindString(env)
			path = strings.Replace(env, ver, "", -1)
		}
		return path
	}

	file, err := exec.LookPath(NODE)
	if err != nil {
		if file, err := exec.LookPath(GNVM); err != nil {
			path = getCurrentPath()
		} else {
			path = strings.Replace(file, DIVIDE+GNVM, "", -1)
		}
	} else {
		path = strings.Replace(file, DIVIDE+NODE, "", -1)
	}

	// gnvm.exe and node.exe the same path
	if path == "." {
		path = getCurrentPath()
	}

	return path
}
开发者ID:Kenshin,项目名称:gnvm,代码行数:29,代码来源:util.go

示例2: ensureFuseVersionIsInstalled

func ensureFuseVersionIsInstalled() error {
	// see if fuse-version is there
	if _, err := exec.LookPath("fuse-version"); err == nil {
		return nil // got it!
	}

	// try installing it...
	log.Debug("fuse-version: no fuse-version. attempting to install.")
	cmd := exec.Command("go", "get", "github.com/jbenet/go-fuse-version/fuse-version")
	cmdout := new(bytes.Buffer)
	cmd.Stdout = cmdout
	cmd.Stderr = cmdout
	if err := cmd.Run(); err != nil {
		// Ok, install fuse-version failed. is it they dont have fuse?
		cmdoutstr := cmdout.String()
		if strings.Contains(cmdoutstr, errStrNoFuseHeaders) {
			// yes! it is! they dont have fuse!
			return fmt.Errorf(errStrFuseRequired)
		}

		log.Debug("fuse-version: failed to install.")
		s := err.Error() + "\n" + cmdoutstr
		return fmt.Errorf(errStrNeedFuseVersion, fuseVersionPkg, dontCheckOSXFUSEConfigKey, s)
	}

	// ok, try again...
	if _, err := exec.LookPath("fuse-version"); err != nil {
		log.Debug("fuse-version: failed to install?")
		return fmt.Errorf(errStrNeedFuseVersion, fuseVersionPkg, dontCheckOSXFUSEConfigKey, err)
	}

	log.Debug("fuse-version: install success")
	return nil
}
开发者ID:qnib,项目名称:go-ipfs,代码行数:34,代码来源:mount_darwin.go

示例3: init

func init() {
	gifsicleCmd, _ = exec.LookPath("gifsicle")
	if Backend() == "GraphicsMagick" {
		maxGifTries = 3
		convertCmd, _ = exec.LookPath("convert")
	}
}
开发者ID:kitak,项目名称:magick,代码行数:7,代码来源:gif.go

示例4: detectVBoxManageCmd

func detectVBoxManageCmd() string {
	cmd := "VBoxManage"
	if p := os.Getenv("VBOX_INSTALL_PATH"); p != "" {
		if path, err := exec.LookPath(filepath.Join(p, cmd)); err == nil {
			return path
		}
	}

	if p := os.Getenv("VBOX_MSI_INSTALL_PATH"); p != "" {
		if path, err := exec.LookPath(filepath.Join(p, cmd)); err == nil {
			return path
		}
	}

	// Look in default installation path for VirtualBox version > 5
	if path, err := exec.LookPath(filepath.Join("C:\\Program Files\\Oracle\\VirtualBox", cmd)); err == nil {
		return path
	}

	// Look in windows registry
	if p, err := findVBoxInstallDirInRegistry(); err == nil {
		if path, err := exec.LookPath(filepath.Join(p, cmd)); err == nil {
			return path
		}
	}

	return detectVBoxManageCmdInPath() //fallback to path
}
开发者ID:NeilW,项目名称:machine,代码行数:28,代码来源:virtualbox_windows.go

示例5: setPointToPoint

func (ti *testInterface) setPointToPoint(suffix int, local, remote string) error {
	ti.name = fmt.Sprintf("gotest%d", suffix)
	ti.local = local
	ti.remote = remote
	xname, err := exec.LookPath("ip")
	if err != nil {
		return err
	}
	ti.setupCmds = append(ti.setupCmds, &exec.Cmd{
		Path: xname,
		Args: []string{"ip", "tunnel", "add", ti.name, "mode", "gre", "local", local, "remote", remote},
	})
	ti.teardownCmds = append(ti.teardownCmds, &exec.Cmd{
		Path: xname,
		Args: []string{"ip", "tunnel", "del", ti.name, "mode", "gre", "local", local, "remote", remote},
	})
	xname, err = exec.LookPath("ifconfig")
	if err != nil {
		return err
	}
	ti.setupCmds = append(ti.setupCmds, &exec.Cmd{
		Path: xname,
		Args: []string{"ifconfig", ti.name, "inet", local, "dstaddr", remote},
	})
	return nil
}
开发者ID:qunhu,项目名称:go_src_comment,代码行数:26,代码来源:interface_linux_test.go

示例6: main

func main() {
	c := CgiServer()
	c.DefaultApp = "blosxom.cgi"
	c.LangMap[".cgi"], _ = exec.LookPath("perl")
	c.LangMap[".php"], _ = exec.LookPath("php-cgi")
	ListenAndServe(":8080", c)
}
开发者ID:mattn,项目名称:go-cgiserver,代码行数:7,代码来源:server.go

示例7: main

func main() {
	if len(os.Args) < 2 {
		log.Fatal("Usage")
	}

	path, err := exec.LookPath("./" + os.Args[1])
	if err != nil {
		path, err = exec.LookPath(os.Args[1])
		if err != nil {
			os.Exit(127)
		}
	}

	sigs := make(chan os.Signal, 1) // There is a go routine so I think capacity 1 is enough
	signal.Notify(sigs, syscall.SIGHUP)

	cmd := exec.Command(path)
	cmd.Args = os.Args[2:]
	// WTF is S_IRUSR | S_IWUSR, hoping its 0600
	logFile, err := os.OpenFile("nohup.out", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0600)
	if err != nil {
		log.Fatal("TODO: create it in $HOME")
	}
	cmd.Stdout = logFile
	if err := cmd.Start(); err != nil {
		log.Fatal(err)
	}
	go handleSigs(sigs)
	fmt.Println("Pid of the started process: ", cmd.Process.Pid)
	cmd.Wait()
	sendEmail(cmd)
}
开发者ID:Gouthamve,项目名称:gohup,代码行数:32,代码来源:main.go

示例8: openCommand

func openCommand() (string, error) {
	if p, err := exec.LookPath("xdg-open"); err != nil {
		return exec.LookPath("open")
	} else {
		return p, nil
	}
}
开发者ID:ibmendoza,项目名称:dgtk,代码行数:7,代码来源:txdbg.go

示例9: New

/* ============================================================================================ */
func New(environment string, parentId int) *Dialog {
	var err error
	var res = new(Dialog)
	if environment == AUTO || environment == "" {
		for _, pkg := range []string{KDE, GTK, X, CONSOLE} {
			_, err = exec.LookPath(pkg)
			if err == nil {
				res.environment = pkg
				break
			}
		}
		if res.environment == "" {
			fmt.Println("Package not found!\nPlease install " + KDE + " or " + GTK + " or " + X + " or " + CONSOLE)
		}
	} else {
		_, err = exec.LookPath(environment)
		if err == nil {
			res.environment = environment
		} else {
			fmt.Println("Package not found!\nPlease install " + environment)
		}
	}

	if res.environment == "" {
		os.Exit(1)
	}

	res.parentId = parentId
	res.reset()
	return res
}
开发者ID:PavelVershinin,项目名称:GoDialogs,代码行数:32,代码来源:dialog.go

示例10: ProcessExternal

func ProcessExternal(page *gostatic.Page, args []string) error {
	if len(args) < 1 {
		return errors.New("'external' rule needs a command name")
	}
	cmdName := args[0]
	cmdArgs := args[1:]

	path, err := exec.LookPath(cmdName)
	if err != nil {
		path, err = exec.LookPath(filepath.Join(page.Site.Base, cmdName))
		if err != nil {
			return fmt.Errorf("command '%s' not found", cmdName)
		}
	}

	cmd := exec.Command(path, cmdArgs...)
	cmd.Stdin = strings.NewReader(page.Content())
	cmd.Dir = page.Site.Base
	var stderr bytes.Buffer
	cmd.Stderr = &stderr
	data, err := cmd.Output()
	if err != nil {
		return fmt.Errorf("'%s' failed: %s\n%s",
			strings.Join(args, " "), err, stderr.String())
	}

	page.SetContent(string(data))
	return nil
}
开发者ID:mchudgins,项目名称:gostatic,代码行数:29,代码来源:external.go

示例11: openURL

func openURL(url string) error {
	var command string
	var args []string
	switch runtime.GOOS {
	case "darwin":
		command = "open"
		args = []string{command, url}
	case "windows":
		command = "cmd"
		args = []string{"/c", "start " + url}
	default:
		if _, err := exec.LookPath("xdg-open"); err != nil {
			log.Println("xdg-open is required to open web pages on " + runtime.GOOS)
			os.Exit(2)
		}
		command = "xdg-open"
		args = []string{command, url}
	}
	if runtime.GOOS != "windows" {
		p, err := exec.LookPath(command)
		if err != nil {
			log.Printf("Error finding path to %q: %s\n", command, err)
			os.Exit(2)
		}
		command = p
	}
	return sysExec(command, args, os.Environ())
}
开发者ID:shaunduncan,项目名称:hk,代码行数:28,代码来源:main.go

示例12: validateEnvironment

func validateEnvironment() {
	var err error
	workingDirectory, err = os.Getwd()
	if err != nil {
		fmt.Fprintln(os.Stderr, "Can't find the working directory")
		os.Exit(1)
	}

	path, err := exec.LookPath(pathToLessc)
	if err != nil {
		fmt.Fprintf(os.Stderr, "The lessc path provided (%s) is invalid\n", path)
		os.Exit(1)
	}

	if enableCSSMin {
		if pathToCSSMin == "" {
			fmt.Fprintf(os.Stderr, "CSS minification invoked but no path provided\n")
			os.Exit(1)
		}

		path, err := exec.LookPath(pathToCSSMin)
		if err != nil {
			fmt.Fprintf(os.Stderr, "CSS minification invoked but the path provided (%s) is invalid\n", path)
			os.Exit(1)
		}
	}
}
开发者ID:jimmysawczuk,项目名称:less-tree,代码行数:27,代码来源:main.go

示例13: init

func init() {
	var err error

	// The executable name will be the directory name.
	if program, err = os.Getwd(); err != nil {
		log.Fatal(err)
	}
	program = filepath.Base(program)

	if _, err = exec.LookPath(program); err != nil {
		if err.(*exec.Error).Err == exec.ErrNotFound {
			if err = exec.Command("go", "install").Run(); err != nil {
				log.Fatal(err)
			}

			log.Printf("Installed %s", program)
		} else {
			log.Fatal(err)
		}
	}

	path, err := exec.LookPath(program)
	if err == nil {
		log.Printf("Using %s at %s", program, path)
	} else {
		log.Fatal(err)
	}
}
开发者ID:jbenet,项目名称:apiproxy,代码行数:28,代码来源:apiproxy_test.go

示例14: manageSymlinks

// (Un)install symbolic runlevel links
func (s *sysv) manageSymlinks(confPath string, install bool) error {
	var cmd *exec.Cmd

	if _, err := exec.LookPath("chkconfig"); err == nil {
		if install {
			cmd = exec.Command("chkconfig", "--add", s.Name)
		} else {
			cmd = exec.Command("chkconfig", "--del", s.Name)
		}
	} else if _, err := exec.LookPath("update-rc.d"); err == nil {
		if install {
			cmd = exec.Command("update-rc.d", s.Name, "defaults")
		} else {
			cmd = exec.Command("update-rc.d", "-f", s.Name, "remove")
		}
	}

	if cmd != nil {
		if err := cmd.Run(); err != nil {
			return fmt.Errorf("Failed to run %q: %s", strings.Join(cmd.Args, " "), err)
		}
	} else {
		/* Manually install/remove symlinks */
		var base = "/etc"

		/* Debian/ubuntu use /etc/rc[0-6].d; RedHat uses /etc/rc.d/rc[0-6].d */
		if _, err := os.Stat("/etc/rc.d/"); err == nil {
			base = "/etc/rc.d"
		} else if _, err := os.Stat(base + "/rc0.d"); os.IsNotExist(err) {
			fmt.Fprintf(os.Stderr, "FIXME: no suitable rc.d directory found in /etc")
			os.Exit(1)
		}

		for _, i := range strings.Split(defaultStartLevels, "") {
			path := fmt.Sprintf("%s/rc%s.d/S%s%s", base, i, defaultStartPriority, s.Name)
			if install {
				if err := os.Symlink(confPath, path); err != nil {
					return fmt.Errorf("Failed to create startup link %s: %s", path, err)
				}
			} else {
				if err := os.Remove(path); err != nil {
					return fmt.Errorf("Failed to remove startup link %s: %s", path, err)
				}
			}
		}
		for _, i := range strings.Split(defaultStopLevels, "") {
			path := fmt.Sprintf("%s/rc%s.d/K%s%s", base, i, defaultStopPriority, s.Name)
			if install {
				if err := os.Symlink(confPath, path); err != nil {
					return fmt.Errorf("Failed to create shutdown link %s: %s", path, err)
				}
			} else {
				if err := os.Remove(path); err != nil {
					return fmt.Errorf("Failed to remove shutdown link %s: %s", path, err)
				}
			}
		}
	}
	return nil
}
开发者ID:grrtrr,项目名称:golang-kardianos-service,代码行数:61,代码来源:service_sysv_linux.go

示例15: initGcloud

func (c *Config) initGcloud() error {
	//  check that gcloud is installed
	_, err := exec.LookPath("gcloud")
	if err != nil {
		return fmt.Errorf("gcloud cli is not installed.  Please install and try again\n")
	}

	//  check that java is installed
	_, err = exec.LookPath("java")
	if err != nil {
		return fmt.Errorf("java jre (at least) is not installed.  Please install and try again\n")
	}

	auth_cmd := exec.Command("gcloud", "--verbosity=debug", "auth", "activate-service-account", "--key-file", c.CredentialsFile)
	var stdout, stderr bytes.Buffer
	auth_cmd.Stdout = &stdout
	auth_cmd.Stderr = &stderr
	err = auth_cmd.Run()
	if err != nil {
		return fmt.Errorf("gcloud auth failed with error: %s and stdout of %s\n", stderr.String(), stdout.String())
	}

	// verify that datacloud functions are installed
	//  this will need to be updated when they come out of alpha
	datacloud_cmd := exec.Command("gcloud", "alpha", "dataflow", "-h")
	err = datacloud_cmd.Run()
	if err != nil {
		return fmt.Errorf("gcloud dataflow commands not installed.\n")
	}

	return nil
}
开发者ID:22Acacia,项目名称:terraform-provider-googlecli,代码行数:32,代码来源:config.go


注:本文中的os/exec.LookPath函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。