英文:
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)
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论