如何在Progress-4GL中捕获OS-COMMAND结果? [英] How to catch OS-COMMAND results in Progress-4GL?

查看:106
本文介绍了如何在Progress-4GL中捕获OS-COMMAND结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用日志记录功能,如此其他文章中所述:

I'm using the logging facilities, as described in this other post:

OUTPUT TO VALUE("C:\Temp_Folder\logfile.txt").
...
PUT UNFORMATTED "Start : Check-zones" SKIP.
...
OUTPUT CLOSE.

这很好.

现在,我想在输出文件中添加 OS-COMMAND 的结果.
我已经尝试了以下方法:(将结果放入新创建的文件中)

Now I would like to add the results of an OS-COMMAND in the output file.
I've already tried the following: (putting the results in a newly to be created file)

OS-COMMAND NO-WAIT VALUE("WMIC printer get name, deviceID >> C:\Temp_Folder\Printers.txt").

这很好用.
因此,我知道命令运行正常.但是,以下内容不起作用:

This is working fine.
So, I know the command is working fine. However, the following is not working:

OS-COMMAND NO-WAIT VALUE("WMIC printer get name, deviceID >> C:\Temp_Folder\LogFile.txt").

这很明显,因为 C:\ Temp_Folder \ Logfile.txt 已被进度应用程序锁定以进行写入,因此,由 OS-COMMAND 打开的外壳可以不要写入该文件.

This is obvious, because C:\Temp_Folder\Logfile.txt is locked for writing by the progress application, so the shell, opened by OS-COMMAND can't write to that file.

为了克服这个问题,我想了解一下 OS-COMMAND 结果的结果.

In order to overcome this, I would like to catch the results of the OS-COMMAND's results.

我该怎么做?

推荐答案

不幸的是,在设计os-command的黑暗年代,它被认为可以抑制所有错误.

Unfortunately back in the dark ages when os-command was designed, it was considered useful to suppress all errors.

您可以启动一个批处理文件,然后让它做一些保证的"输出错误处理,请参见 https://knowledgebase.progress.com/articles/Article/21039

You can either start a batch file and let that do some "guaranteed" output error handling, see https://knowledgebase.progress.com/articles/Article/21039

或者(因为您在Windows上),您可以使用.Net

Or (since you are on Windows) you can use the .Net system diagnostics process class (which you will want to wrap in your own method or function to simplify use):

DEFINE VARIABLE oProcess   AS System.Diagnostics.Process NO-UNDO.
DEFINE VARIABLE lcstderr   AS LONGCHAR    NO-UNDO.
DEFINE VARIABLE lcstdout   AS LONGCHAR    NO-UNDO.

oProcess = NEW System.Diagnostics.Process().

oProcess:StartInfo:FileName = "wmic.exe".
oProcess:StartInfo:Arguments = "printer get name, deviceID".
oProcess:StartInfo:CreateNoWindow         =  TRUE.
oProcess:StartInfo:UseShellExecute        =  FALSE.
oProcess:StartInfo:RedirectStandardError  =  TRUE.
oProcess:StartInfo:RedirectStandardOutput =  TRUE.
oProcess:Start().

lcstdout = oProcess:StandardOutput:ReadToEnd().
lcstderr = oProcess:StandardError:ReadToEnd().

oProcess:WaitForExit().

lcstdout = lcstdout + oProcess:StandardOutput:ReadToEnd().
lcstderr  = lcstderr + oProcess:StandardError:ReadToEnd().

这篇关于如何在Progress-4GL中捕获OS-COMMAND结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆