问题描述

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

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
 go:找不到命令
go: command not found

推荐答案

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

package main

func main() {
    println("Hello World!")
}
 chmod + x file.go  ./ file.go p1 p2 
chmod +x file.go./file.go p1 p2

编辑:这适用于Ubuntu。我没有看到OSX有问题。

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

这篇关于从shell脚本运行Golang脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!