英文:
What is the equivalent of Java's System.out.println() in Progress ABL?
问题
Sure, here is the translated content:
我正在尝试在Progress ABL中实现Java的`System.out.println()`方法。
最接近的功能似乎是:
**test.p:**
MESSAGE "hello world" SKIP.
我运行了以下测试以查看它是否起作用:
Windows
FAIL C:\opt\prgs\dlc117\bin\prowin -b -p test.p
OK C:\opt\prgs\dlc117\bin\prowin -b -p test.p | % ToString
OK C:\opt\prgs\dlc117\bin\_progres -b -p test.p
OK C:\opt\prgs\dlc117\bin\_progres -b -p test.p | % ToString
Unix
TODO
**因此,最终我会这样实现它:**
METHOD STATIC PUBLIC VOID println(i_cText AS CHAR):
MESSAGE i_cText SKIP.
PAUSE 0.
CATCH oError AS CLASS Progress.Lang.Error:
/* 抑制错误,因为MESSAGE不支持NO-ERROR。 */
END.
END.
我还没有找到一种知道`MESSAGE`何时失败的方法。我尝试检查`OPSYS`、`TERMINAL`和`SESSION:BATCH-MODE`,但它们不可靠。我需要知道是否存在“默认输出”,但该如何实现?
Please note that I've retained the code parts without translation as you requested.
英文:
I'm trying to implement Java's System.out.println()
method in Progress ABL
.
The closest functionality seems to be:
test.p:
MESSAGE "hello world" SKIP.
I ran the following tests to see if it works:
Windows
FAIL C:\opt\prgs\dlc117\bin\prowin -b -p test.p
OK C:\opt\prgs\dlc117\bin\prowin -b -p test.p | % ToString
OK C:\opt\prgs\dlc117\bin\_progres -b -p test.p
OK C:\opt\prgs\dlc117\bin\_progres -b -p test.p | % ToString
Unix
TODO
So in the end, I'd implement it like this:
METHOD STATIC PUBLIC VOID println(i_cText AS CHAR):
MESSAGE i_cText SKIP.
PAUSE 0.
CATCH oError AS CLASS Progress.Lang.Error:
/* Suppress error because MESSAGE doesn't support NO-ERROR. */
END.
END.
I haven't found a way to know when the MESSAGE
will fail. I tried checking OPSYS
, TERMINAL
and SESSION:BATCH-MODE
but they are not reliable. I'd need to know if default output
exists but how?
答案1
得分: 1
据我了解,您始终需要重定向才能批量执行。您不重定向的命令行会导致错误。一旦重定向,下面的代码将写入标准输出。在Linux上可以使用| tee
,在PowerShell上可以使用| % ToString
。结果如下所示。
英文:
AFIAK you always have to redirect in order to execute in batch.
Your commandline without redirecting results in
---------------------------
Error
---------------------------
** Attempt to write with no current output destination. (516)
---------------------------
Once you redirect, code below will write to stdout.
put unformatted "put Hello world".
message "message Hello world".
display "display Hello world".
quit.
you can use | tee
on linux or | % ToString
in powershell
result
prowin.exe -b -p .\helloworld_stdout.p | % ToString
put Hello world
message Hello world
display Hello world
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论