Lotus Notes FAQ Visit Our Sponsor!

How Do You Run Console Commands From Lotuscript?

Here's an example of code (from Daniel Nashed) on how you can issue Remote Console commands from Lotuscript:

Dim rcmd_server As String
Dim rcmd_command As String     
Dim rcmd_result as String

rcmd_server = "notes.nashcom.de"
rcmd_command = "show server"

Dim remoteConsole As New RemoteConsole (rcmd_server)

recmd_result = remoteConsole.Execute (rcmd_command)

REM W32 De
clares
Declare Function W32_NSFRemoteConsole Lib "NNOTES.DLL" Alias "NSFRemoteConsole" (Byval server As Lmbcs String, Byval cmd As Lmbcs String, ret As Long) As Integer
Declare Function W32_OSLockObject  Lib "NNOTES.DLL" Alias "OSLockObject" (Byval handle As Long) As Lmbcs String
Declare Sub W32_OSUnlockObject  Lib "NNOTES.DLL" Alias "OSUnlockObject" (Byval handle As Long) 
Declare Sub W32_OSMemFree  Lib "NNOTES.DLL" Alias "OSMemFree" (Byval handle As Long)
Declare Function W32_OSLoadString Lib "NNOTES.DLL" Alias "OSLoadString" (Byval hModule As Long, Byval stringCode As Integer, _
Byval retBuffer As Lmbcs String, Byval bufferLen As Integer) As Integer

REM MAC Declares
Declare Function MAC_NSFRemoteConsole Lib "NotesLib" Alias "NSFRemoteConsole" (Byval server As Lmbcs String, Byval cmd As Lmbcs String, ret As Integer) As Integer
Declare Function MAC_OSLockObject  Lib "NotesLib" Alias "OSLockObject" (Byval handle As Integer) As Lmbcs String
Declare Sub MAC_OSUnlockObject  Lib "NotesLib" Alias "OSUnlockObject" (Byval handle As Integer) 
Declare Sub MAC_OSMemFree  Lib "NotesLib" Alias "OSMemFree" (Byval handle As Integer)
Declare Function MAC_OSLoadString Lib "NotesLib" Alias "OSLoadString" (Byval hModule As Integer, Byval stringCode As Integer, _
Byval retBuffer As Lmbcs String, Byval bufferLen As Integer) As Integer

REM Linux Declares
Declare Function LINUX_NSFRemoteConsole Lib "libnotes.so" Alias "NSFRemoteConsole" (Byval server As Lmbcs String, Byval cmd As Lmbcs String, ret As Long) As Integer
Declare Function LINUX_OSLockObject  Lib "libnotes.so" Alias "OSLockObject" (Byval handle As Long) As Lmbcs String
Declare Sub LINUX_OSUnlockObject  Lib "libnotes.so" Alias "OSUnlockObject" (Byval handle As Long) 
Declare Sub LINUX_OSMemFree  Lib "libnotes.so" Alias "OSMemFree" (Byval handle As Long)
Declare Function LINUX_OSLoadString Lib "libnotes.so" Alias "OSLoadString" (Byval hModule As Long, Byval stringCode As Integer, _
Byval retBuffer As Lmbcs String, Byval bufferLen As Integer) As Integer

REM AIX Declares
Declare Function AIX_NSFRemoteConsole Lib "libnotes_r.a" Alias "NSFRemoteConsole" (Byval server As Lmbcs String, Byval cmd As Lmbcs String, ret As Integer) As Integer
Declare Function AIX_OSLockObject  Lib "libnotes_r.a" Alias "OSLockObject" (Byval handle As Integer) As Lmbcs String
Declare Sub AIX_OSUnlockObject  Lib "libnotes_r.a" Alias "OSUnlockObject" (Byval handle As Integer) 
Declare Sub AIX_OSMemFree  Lib "libnotes_r.a" Alias "OSMemFree" (Byval handle As Integer)
Declare Function AIX_OSLoadString Lib "libnotes_r.a" Alias "OSLoadString" (Byval hModule As Integer, Byval stringCode As Integer, _
Byval retBuffer As Lmbcs String, Byval bufferLen As Integer) As Integer

REM Solaris Declares
Declare Function SOLARIS_NSFRemoteConsole Lib "libnotes.so" Alias "NSFRemoteConsole" (Byval server As Lmbcs String, Byval cmd As Lmbcs String, ret As Integer) As Integer
Declare Function SOLARIS_OSLockObject  Lib "libnotes.so" Alias "OSLockObject" (Byval handle As Integer) As Lmbcs String
Declare Sub SOLARIS_OSUnlockObject  Lib "libnotes.so" Alias "OSUnlockObject" (Byval handle As Integer) 
Declare Sub SOLARIS_OSMemFree  Lib "libnotes.so" Alias "OSMemFree" (Byval handle As Integer)
Declare Function SOLARIS_OSLoadString Lib "libnotes.so" Alias "OSLoadString" (Byval hModule As Integer, Byval stringCode As Integer, _
Byval retBuffer As Lmbcs String, Byval bufferLen As Integer) As Integer

Class RemoteConsole
Public IsError As Variant
Private rc As Integer
Private Long_hBuffer As Long
Private Integer_hBuffer As Integer
Private Server As String
Private Command As String
Private Result As String
Sub New (InputServer As String)
If InputServer = "" Then
Me.IsError = True
Else
Me.Server = InputServer
Me.IsError = False
End If
End Sub
Function get_platform () As String
Dim tmp_platform As Variant
Dim lower_platform As String
tmp_platform = Evaluate(|@Implode(@Platform([Specific]);" ")|)
lower_platform = Lcase(Cstr(tmp_platform(0)))
REM Messagebox Cstr(tmp_platform(0))
If (Instr (lower_platform, "aix")) Then
get_platform = "aix"
Elseif (Instr (lower_platform, "solaris")) Then
get_platform = "solaris"
Elseif (Instr (lower_platform, "linux")) Then
get_platform = "linux"
Elseif (Instr (lower_platform, "win")) Then
get_platform = "w32"
Elseif (Instr (lower_platform, "mac")) Then
get_platform = "mac"
Else
Messagebox "Unsupported Platform : >" + lower_platform + "<"
get_platform = ""
End If
End Function
Function Execute (InputCommand As String) As String
Dim StrLen As Integer
Dim errorStr As String * 1024
Dim Session As New NotesSession
Dim platform As String
platform = get_platform
REM Messagebox session.platform
REM Messagebox platform
If Me.Server = "" Then
Me.Execute = "No server specified"
Me.IsError = True
Exit Function
End If
If InputCommand = "" Then
Me.Execute = "No command specified"
Me.IsError = True
Exit Function
End If
Me.command = InputCommand + Chr (0)
Me.server = Me.server + Chr(0)
Select Case platform
Case "w32"
Me.rc = W32_NSFRemoteConsole (Me.Server, Me.Command, Long_hBuffer)
Case "mac"
Me.rc = MAC_NSFRemoteConsole (Me.Server, Me.Command, Integer_hBuffer)
Case "linux"
Me.rc = LINUX_NSFRemoteConsole (Me.Server, Me.Command, Long_hBuffer)
Case "aix"
Me.rc = AIX_NSFRemoteConsole (Me.Server, Me.Command, Integer_hBuffer)
Case "solaris"
Me.rc = SOLARIS_NSFRemoteConsole (Me.Server, Me.Command, Integer_hBuffer)
Case Else
Exit Function
End Select
If (Me.rc <> 0) Then
Me.IsError = True
Select Case platform
Case "w32"
StrLen = w32_OSLoadString(0&, Me.rc, errorStr , Len(errorStr) - 1)
Case "mac"
StrLen = MAC_OSLoadString(0&, Me.rc, errorStr , Len(errorStr) - 1)
Case "linux"
StrLen = LINUX_OSLoadString(0&, Me.rc, errorStr , Len(errorStr) - 1)
Case "aix"
StrLen = AIX_OSLoadString(0&, Me.rc, errorStr , Len(errorStr) - 1)
Case "solaris"
StrLen = SOLARIS_OSLoadString(0&, Me.rc, errorStr , Len(errorStr) - 1)
Case Else
Exit Function
End Select
If (StrLen = 0 ) Then
errorStr = ""
End If
Me.Result= "Error: [" & Cstr (rc) & "] " + errorStr
Else
Select Case platform
Case "w32"
Me.Result = W32_OsLockObject (Long_hBuffer) + Chr (0)
Call W32_OSUnlockObject (Long_hBuffer)
Call W32_OsMemFree (Long_hBuffer)
Case "mac"
Me.Result = MAC_OsLockObject (Integer_hBuffer) + Chr (0)
Call MAC_OSUnlockObject (Integer_hBuffer)
Call MAC_OsMemFree (Integer_hBuffer)
Case "linux"
Me.Result = LINUX_OsLockObject (Long_hBuffer) + Chr (0)
Call LINUX_OSUnlockObject (Long_hBuffer)
Call LINUX_OsMemFree (Long_hBuffer)
Case "aix"
Me.Result = AIX_OsLockObject (Integer_hBuffer) + Chr (0)
Call AIX_OSUnlockObject (Integer_hBuffer)
Call AIX_OsMemFree (Integer_hBuffer)
Case "solaris"
Me.Result = SOLARIS_OsLockObject (Integer_hBuffer) + Chr (0)
Call SOLARIS_OSUnlockObject (Integer_hBuffer)
Call SOLARIS_OsMemFree (Integer_hBuffer)
Case Else
Exit Function
End Select
Me.IsError = False
End If
Me.Execute = Me.Result
End Function End Class


Applies to Notes Versions: 4 4.5 4.6 5 6 6.5 7
Last Modified: January 21, 2005