英文:
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
它可以正常运行,但不幸的是在完成后会自动关闭。
你能帮忙解决这个问题吗?
英文:
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?
答案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?
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论