在MacOS上使用Golang执行命令

huangapple go评论76阅读模式
英文:

command execution on MacOSx in golang

问题

我有一个简单的Go语言程序,用于在MacOSx上启动一个应用程序。

package main

import (
	"io"
	"log"
	"os/exec"
)

func main() {
	out1, err1 := exec.Command("/usr/bin/open", "-a", "calculator").Output()
	log.Printf("output is err", err1)
	log.Printf("output is out", out1)
}

我期望在执行后它能启动计算器应用程序,但是我收到以下错误信息:

2017/04/26 16:01:26 output is err%!(EXTRA *os.PathError=fork/exec /usr/bin/open : no such file or directory) 2017/04/26 16:01:26 output is out%!(EXTRA []uint8=[])

我正在尝试在OSx 10.11上运行它。

英文:

I have a simple golang program to start an application in MacOSx.

package main

import (
	"io"
	"log"
	"os/exec"
)
func main() {
out1,err1 := exec.Command("/usr/bin/open ", " -a", "calcultor").Output()
log.Printf(" output is err  ", err1)
log.Printf(" output is err  ", out1)

}

I expect it to start application in calculator after execution but i receive following errors

> 2017/04/26 16:01:26 output is err%!(EXTRA *os.PathError=fork/exec
> /usr/bin/open : no such file or directory) 2017/04/26 16:01:26 output
> is out%!(EXTRA []uint8=[])

I am trying it on OSx 10.11.

答案1

得分: 1

有一个拼写错误 - "calcultor" 应该是 "calculator"。

英文:

There's a spelling mistake - "calcultor" should be "calculator".

huangapple
  • 本文由 发表于 2017年4月26日 20:03:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/43633662.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定