在运行.exe文件(Windows)时保持提示窗口打开。

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

Keep prompt window open when running .exe (windows)

问题

我有一个快速脚本,从文本文件中抓取一些数据,并将一些总结结果输出给用户。当在Windows上通过双击可执行文件运行时,它只会快速运行并关闭命令提示符窗口,无法看到程序的结果。我知道我可以进入命令提示符并从那里运行它。但是,有没有办法在用户双击.exe文件运行时保持窗口打开,以便可以看到结果呢?

英文:

I have a quick script that is scraping some data from a text file and outputting some summarized results to the user. When this is ran on windows by double clicking the executable it just runs real fast and closes the command prompt and the results of the program cannot be seen. I know I can go into command prompt and run it from there. But, is there anything I can do for when a user double clicks the .exe file to run it to keep that window open so results can be seen?

答案1

得分: 3

一个技巧是在你的应用程序末尾等待用户输入。一旦用户按下任意键,就退出应用程序。代码片段如下:

func main() {
    //你的原始代码...
    
    fmt.Printf("按任意键退出...")
    b := make([]byte, 1)
    os.Stdin.Read(b)
}
英文:

One trick is by waiting user input at the end of your application. Once user press any key, exit the application. The snippet:

func main() {
    //Your original code...
    
    fmt.Printf("Press any key to exit...")
    b := make([]byte, 1)
    os.Stdin.Read(b)
}

huangapple
  • 本文由 发表于 2017年6月10日 10:38:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/44468995.html
匿名

发表评论

匿名网友

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

确定