diff options
author | Jean-Pierre Ledure <jp@ledure.be> | 2024-03-23 17:41:49 +0100 |
---|---|---|
committer | Jean-Pierre Ledure <jp@ledure.be> | 2024-03-24 17:35:49 +0100 |
commit | e110974bc1c2a0b253d27cf3ad2643aa5208e2cd (patch) | |
tree | f302c8f732340f8c61ccae26966a203a276dd16b /wizards/source | |
parent | ee2afff68ed5b22b2bf635d536584e8cba4ae2a4 (diff) |
ScriptForge (session).RunApplication() redesign
The RunApplication() method uses
- either the Shell() Basic built-in function
(only in asynchronous mode)
- or the com.sun.star.system.SystemShellExecute()
service
in this order.
The second is tried in case of failure of the first one.
Benefits:
- the method can start batch files or scripts
- broader than Shell(): giving a user file as argument
opens its application first based on the file suffix
- more robust error handling
Read discussion in tdf#160222.
This change could require a light revisit of the
sf_session help page.
Change-Id: I1fb4717db4b971bd62885ad0e38b7c08a8e6f434
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165218
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Diffstat (limited to 'wizards/source')
-rw-r--r-- | wizards/source/scriptforge/SF_Session.xba | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/wizards/source/scriptforge/SF_Session.xba b/wizards/source/scriptforge/SF_Session.xba index 307fb7a8f4bf..cc6e576e1c5f 100644 --- a/wizards/source/scriptforge/SF_Session.xba +++ b/wizards/source/scriptforge/SF_Session.xba @@ -563,9 +563,12 @@ Public Function RunApplication(Optional ByVal Command As Variant _ ''' The method does not validate the given parameters, but only passes them to the specified command ''' Returns: ''' True if success +''' Exceptions: +''' UNKNOWNFILEERROR Command could not be identified as a valid file ''' Examples: ''' session.RunApplication("Notepad.exe") ''' session.RunApplication("C:\myFolder\myDocument.odt") +''' session.RunApplication("kate") ' (Linux) ''' session.RunApplication("kate", "/home/me/install.txt") ' (Linux) Dim bReturn As Boolean ' Returned value @@ -585,9 +588,23 @@ Check: End If Try: - Set oShell = SF_Utils._GetUNOService("SystemShellExecute") - sCommand = SF_FileSystem._ConvertToUrl(Command) - oShell.execute(sCommand, Parameters, com.sun.star.system.SystemShellExecuteFlags.DEFAULTS) + ' Cfr. discussion tdf#160222 + ' 1) Try Shell(), always in not synchronized mode + ' 2) If failure - check command existence as a valid file + ' - try com.sun.star.system.SystemShellExecute + sCommand = SF_FileSystem._ConvertFromUrl(Command) + On Local Error GoTo Step2 + Shell(sCommand, , Parameters, False) + Step2: + If Err > 0 Then + On Error GoTo 0 ' Reset error status + If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch + If Not SF_FileSystem.FileExists(Command) Then GoTo CatchNotExists + Set oShell = SF_Utils._GetUNOService("SystemShellExecute") + sCommand = SF_FileSystem._ConvertToUrl(Command) + oShell.execute(sCommand, Parameters, com.sun.star.system.SystemShellExecuteFlags.DEFAULTS) + End If + bReturn = True Finally: @@ -596,6 +613,9 @@ Finally: Exit Function Catch: GoTo Finally +CatchNotExists: + SF_Exception.RaiseFatal(UNKNOWNFILEERROR, "Command", Command) + GoTo Finally End Function ' ScriptForge.SF_Session.RunApplication REM ----------------------------------------------------------------------------- |