从shell脚本中运行Golang脚本。

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

Run Golang script from shell script

问题

我正在尝试在每次登录到OSX时运行我的golang程序。我正在尝试使用Automator和以下脚本:

#!/bin/sh
export GOPATH=/Volumes/DTSE9/worker
go run /Volumes/worker/worker.go

每当我使用Automator运行这个脚本时,它告诉我go: command not found

英文:

I'm trying to run my golang program whenever I log into OSX. I'm trying the following script with Automator:

#!/bin/sh
export GOPATH=/Volumes/DTSE9/worker
go run /Volumes/worker/worker.go

Whenever I run this with Automator, it tells me go: command not found

答案1

得分: 2

创建一个名为file.go的文件,其内容应如下所示:

///path-to/bin/go run $0 $@; exit $?

package main

func main() {
    println("Hello World!")
}

然后运行chmod +x file.go,然后你可以使用./file.go p1 p2来执行它。

编辑:这在Ubuntu上有效。我没有看到有关OSX的问题。

英文:

Create a file like say file.go and it's content should look like:

///path-to/bin/go run $0 $@; exit $?

package main

func main() {
	println("Hello World!")
}

Then run chmod +x file.go and then you can execute it as ./file.go p1 p2.

Edit: This works on Ubuntu. I did not saw that OSX was in question.

huangapple
  • 本文由 发表于 2017年3月18日 03:13:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/42865472.html
匿名

发表评论

匿名网友

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

确定