如何以非零退出状态退出 Forth?

发布于 2025-01-16 21:30:40 字数 440 浏览 4 评论 0原文

我想以非零退出状态退出 Forth 程序(使用 Gforth 0.7.3)。

我已经尝试过了:

1 bye

但是 1 没有被解释为 bye 的参数(而且我也没想到这会起作用;我在文档中找不到 bye 的任何提示 将接受一个参数)。

请注意,我不想触发异常,因为这也会打印错误消息(除非有办法从 Forth 程序本身中抑制异常的错误消息)。

那么,如何将 Forth 程序退出回托管环境/操作系统并提供非零退出状态? (基本上,我正在寻找相当于 return EXIT_FAILURE; // from main() (C) 或 exit(EXIT_FAILURE); (C) 或 System.exit(1); (Java)。)

I would like to exit a Forth program (using Gforth 0.7.3) with a non-zero exit status.

I've tried:

1 bye

But the 1 is not interpreted as an argument to bye (and I didn't expect this to work anyway; I couldn't find any hint in the documentation that bye would accept an argument).

Note that I do not want to trigger an exception, as that also prints an error message (unless there is a way to suppress the error message of the exception from within the Forth program itself).

So, how do I exit a Forth program back to the hosted environment/OS providing a non-zero exit status?
(Basically, I'm looking for the equivalent of return EXIT_FAILURE; // from main() (C) or exit(EXIT_FAILURE); (C) or System.exit(1); (Java).)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

甲如呢乙后呢 2025-01-23 21:30:40

在 Gforth 中,内部字 (bye) ( n -- ) 可用于将退出状态返回给操作系统。

例如,Bash 中的以下命令:

gforth -e '123 (bye)' ; echo $?

打印“123”。

一般来说,返回非零退出状态的方法尚未标准化。

In Gforth, the internal word (bye) ( n -- ) can be used to return the exit status to the OS.

For example, the following command in Bash:

gforth -e '123 (bye)' ; echo $?

prints "123".

In general, a method to return a non-zero exit status is not standardized yet.

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