Search code examples
operating-systemwkhtmltopdfquotesopenedgeprogress-4gl

How to include OS command with Substitute function in Openedge?


Im trying to create an PDF via OS-Command in OpenEdge but I hit an error when I run the script.

*Error : The command "C: \ Program" is either misspelled or could not be found

It works perfectly :

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" ').

However, when I Include the command in script and run it then I encounter an error.

This one doesnt work :

define variable cmdcommand as 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"). os-command value(cmdcommand).

What did I miss here? Can anyone help?


Solution

  • In your second sample, there's no value in using SUBSTITUTE, as your're not using place holders (&1, &2, ...). What you're doing is basically a straight forward string assignment.

    The resulting string looks like this:

    "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"

    • there's an extra space at the beginning
    • there's no space between the closing quote of the path to your exe and the first argument.

    This here works for me:

    define variable cmdcommand as char no-undo.
    
    cmdcommand = SUBSTITUTE ('"c:\Program Files (x86)\WinMerge\winmergeu.exe" &1 &2',
                              "c:\temp\1.txt",
                              "c:\temp\2.txt").
    
    OS-COMMAND silent value(cmdcommand).
    

    Due to the use of the SUBSTITUTE function with place holders, this gives me a clean command with a space between the exe path and the first argument.

    It works with or without the SILENT option.