Handling "@command[execute]" errors

I have a .exe I am trying to launch and pass variables to. I do it by itself it works fine but the kicker is it can be in three different paths on the users HD. If I try all three locations it throws a “Unable to locate program” when it cannot be found.

The end result I am looking for is for Notes to “look” in the three directories without prompting the user with the generic error mentioned above if it cannot be found. I would also like to provide my own error message if possible.

Here is my @formula code, do you see anything wrong here?:

tmp:=“10.10.1.100” ;

@If(@IsError( @Command([Execute]; “C:\Program Files\Funk Software\Proxy Master\Proxy.exe” ; (tmp)) ) ; @Prompt([Ok];“”;“Error finding program 1”) ; “” );

@If(@IsError(@Command([Execute]; “C:\Program Files\Proxy Networks\Proxy Master\Proxy.exe” ; (tmp)) ) ; @Prompt([Ok];“”;“Error finding program 2”) ; “” );

@If(@IsError(@Command([Execute]; “C:\Program Files\Proxy Networks\Proxy Pro Master\Proxy.exe” ; (tmp)) ) ; @Prompt([Ok];“”;“Error finding program 3”) ; “” )

Subject: Handling “@command[execute]” errors

I don’t think you can ever get @Command[Execute] to return anything.

My suggestion is that you run a LotusScript agent first. This agent sets an environment variable to the path to use. The agent can use the Dir method to find the path to the executable.

Something like this:

@Do (

@Command([ToolsRunMacro]; “name of the agent”);

@Command([Execute]; @Environment(“name of env-variable”); (tmp))

)

Subject: RE: Handling “@command[execute]” errors

Thanks for pointing me in the right direction. Rather than putting the LS code in an agent and calling the agent every time I need to run the exe, instead I put the LS code in the database postopen event to set the environment var and I call it with the formula. Also many thanks to Jerry Redman, he suggested some code that eventually led me to this.

Heres my LS code run on database postopen:

Sub Postopen(Source As Notesuidatabase)

Option Declare

Option Public

Dim FilePathStr As String

Dim s As New NotesSession

Dim DirList As Variant

Dim DirNeeded As String

Dim dir1, dir2, dir3, dir4, dir5, dir6 As String

Dim ProgramName As String

dir1 = "C:\..."

dir2 = "C:\..."

dir3 = "C:\..."

dir4 = "C:\..."

dir5 = "C:\..."

dir6 = "C:\..."

ProgramName = "Program.exe"

DirNeeded = ""

'Create an array of the directory names:

DirList = Split(dir1+","+dir2+","+dir3+","+dir4+","+dir5+","+dir6,",")

'Using the FileExists function, loop through DirList and see if the exe is in any of them

ForAll DirName In DirList

	If FileExists( DirName , ProgramName) Then

		DirNeeded = DirName

		Exit ForAll

	End If

End ForAll

'If DirNeeded is null after this, then it didn't find the file, otherwise DirNeeded is the location of the file.

Print  "Your Program Direcotry: " + DirNeeded + ProgramName

Call s.SetEnvironmentVar( "$ProgramMasterPath", DirNeeded + ProgramName, True )

End Sub

Function FileExists (FilePath, FileName As String) As Integer

FileExists = True

FilePathStr = CStr(FilePath) + FileName

On Error Resume Next

If UCase$(Dir$(FilePathStr)) <> UCase$(FileName) Then

	FileExists = False	

End If

End Function

Heres my Formula called from within the form:

tmp:=@Text(“/S”+IPAddressSCI);

tmp2 := @Name([CN];@UserName);

tmpProgramPath := @Environment( “ProgramMasterPath” ) ;

@Command([Execute]; tmpProgramPath ; (tmp) )