如何防止控制台窗口在 ghc 应用程序中关闭?
当我使用 ghc 编译的 Windows 控制台应用程序即将结束时,控制台窗口立即关闭。有时这很好,但当我想从中读取一些文本输出时,这不是很好。所以,现在我将这个丑陋的代码添加到我的应用程序中:
main =
do
...HERE IS THE CODE ...
putStrLn " $$ Every thing have passed well $$ /n Press Enter "
_ <- getLine
return ()
这非常丑陋,而且,当某些错误使我的应用程序崩溃时,控制台窗口会关闭。 另一种方法是在“cmd”控制台中运行程序,但有时并不舒服。有没有什么好看又方便的方法来处理程序输出?
When my windows console app compiled with ghc going to it's end, the console window instantly closes. That is good sometimes, but not very good when I want to read some text output from it. So, now I adding this ugly code to my app:
main =
do
...HERE IS THE CODE ...
putStrLn " $ Every thing have passed well $ /n Press Enter "
_ <- getLine
return ()
And this is quite ugly, and more, when some error crashes my app, the console window closes.
An other way around to run program in 'cmd' console, but it is not comfortable sometimes. Is there any good looking and convenient way for handling program output?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以编写一个简单的 shell 脚本,例如
将其另存为 RunIt.cmd 或其他内容,然后双击该脚本来运行应用程序。它将打开一个控制台窗口,并在窗口关闭之前等待您按任意键,无论 Haskell 做什么。
You could just write a trivial shell script like
Save that as
RunIt.cmd
or something, and then double-click that to run the application. It will open a console window, and wait for you to press any key before the window shuts, regardless of what Haskell does.