首页 > 解决方案 > 如何在 Openedge 中包含具有替换功能的 OS 命令?

问题描述

我试图通过 OpenEdge 中的 OS-Command 创建 PDF,但在运行脚本时遇到错误。

*错误命令“C:\ Program”拼写错误或找不到

它完美地工作:

os-command (' "C:\Program Files (x86)\wkhtmltopdf\wkhtmltopdf.exe" "V:\V11\WEB\PDF\Name_01.03.2021_14.09.30_da.html" "V:\V11\WEB\PDF \Name_01.03.2021_14.09.30_da.pdf"')。

但是,当我在脚本中包含命令并运行它时,我遇到了一个错误

这个不起作用:

将变量 cmdcommand 定义为 char no-undo。cmdcommand = SUBSTITUTE (' "C:\Program Files (x86)\wkhtmltopdf\wkhtmltopdf.exe"
"V:\V11\WEB\PDF\Name_&1_&2_&3.html"
"V:\V11\WEB\PDF\Name_&1_&2_&3.pdf" ' ,“01.03.2021”,“14.09.30”,“da”)。操作系统命令值(cmdcommand)。

我在这里错过了什么?任何人都可以帮忙吗?

标签: operating-systemwkhtmltopdfquotesopenedgeprogress-4gl

解决方案


经过os-command一段时间的努力以得到正常错误并返回输出,如果您只针对 Windows,那么您可能会发现使用 .Net System.Diagnostics.Process类更容易。

为了让你开始:

define variable oProcess as System.Diagnostics.Process no-undo.
define variable oInfo    as System.Diagnostics.ProcessStartInfo no-undo.

oProcess = new System.Diagnostics.Process().
assign 
   oInfo = oProcess:StartInfo
    
   oInfo:FileName         =  "C:~\Program Files (x86)~\winmerge~\winmergeu.exe".
   oInfo:WorkingDirectory =  "session:temp-directory
   oInfo:Arguments        =  substitute(
                                "&1 &2",
                                quoter( "file1.txt" ),
                                quoter( "file2.txt" )
                             )
   .
                
oProcess:Start().
oProcess:WaitForExit().

ProcessStartInfo类的其他有用属性包括:

  • 创建无窗口
  • 使用Shell执行
  • 重定向标准错误
  • 重定向标准输出

推荐阅读