如何防止控制台窗口在 ghc 应用程序中关闭?

发布于 2025-01-06 18:43:15 字数 392 浏览 6 评论 0原文

当我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼中杀气 2025-01-13 18:43:15

您可以编写一个简单的 shell 脚本,例如

MyApp.exe
PAUSE

将其另存为 RunIt.cmd 或其他内容,然后双击该脚本来运行应用程序。它将打开一个控制台窗口,并在窗口关闭之前等待您按任意键,无论 Haskell 做什么。

You could just write a trivial shell script like

MyApp.exe
PAUSE

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文