当我通过下拉菜单运行Go脚本时,如何防止.bat文件关闭?

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

Prevent .bat file closing when I run Go script via drop down

问题

我有一个用Go编写的小Hello World程序:

package main

import "fmt"

func main() {
    fmt.Printf("hello, world\n")
}

我使用Sublime Text 3和GoSublime。可能配置有问题,因为工具->构建命令不起作用,只有在控制台中输入以下命令才有效:

go build

然后编辑器会创建.exe程序。

所以我想使用一个基本的.bat文件,我可以将我的hello.go程序拖放到其中:

@echo off
cd /d "%~dp0"
start "" "C:\Go\bin\go.exe" "run" "%~f1" pause

它可以正常运行,但不幸的是在完成后会自动关闭。

你能帮忙解决这个问题吗? 当我通过下拉菜单运行Go脚本时,如何防止.bat文件关闭?

英文:

I have this little Hello World program written in Go:

package main

import "fmt"

func main() {
    fmt.Printf("hello, world\n")
}

I use Sublime Text 3 with GoSublime. Something misconfigured, because Tools -> Build command not working, just only when I type in the console:

go build

Then the editor creating the .exe program.

So I want to use a basic .bat file, where I drag and drop my hello.go program:

@echo off
cd /d "%~dp0"
start "" "C:\Go\bin\go.exe" "run" "%~f1" pause

It runs without problem, but unfortunately closes when it's finished.

Can You help to solve this? 当我通过下拉菜单运行Go脚本时,如何防止.bat文件关闭?

答案1

得分: 2

只是start命令在自己的进程中启动它吗?

所以:

@echo off
cd /d "%~dp0"
C:\Go\bin\go.exe run %~f1 
pause

这样可以工作吗?

英文:

It's just that start launches it in it's own process?

so:

@echo off
cd /d "%~dp0"
C:\Go\bin\go.exe run %~f1 
pause

Should work?

huangapple
  • 本文由 发表于 2014年9月11日 20:00:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/25786918.html
匿名

发表评论

匿名网友

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

确定