NudeDude
NudeDude

Reputation: 25

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?

Upvotes: 0

Views: 367

Answers (2)

Stefan Drissen
Stefan Drissen

Reputation: 3379

After having fought with os-command for quite some time to get normal errors and output returned, if you are only targeting Windows then it you may find it easier to use the .Net System.Diagnostics.Process class.

To get you started:

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().

Other useful properties of the ProcessStartInfo class include:

  • CreateNoWindow
  • UseShellExecute
  • RedirectStandardError
  • RedirectStandardOutput

Upvotes: 1

Mike Fechner
Mike Fechner

Reputation: 7192

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.

Upvotes: 0

Related Questions