Bug 161405 - ScriptForge's RunApplication does not open files with CJK in the filename.
Summary: ScriptForge's RunApplication does not open files with CJK in the filename.
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
24.2.3.2 release
Hardware: All Windows (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: ScriptForge
  Show dependency treegraph
 
Reported: 2024-06-04 02:46 UTC by nobu
Modified: 2024-07-09 13:25 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description nobu 2024-06-04 02:46:15 UTC
Description:
ScriptForge's RunApplication functions cannot be opened if the filename contains CJK.

Steps to Reproduce:
1. open new calc and save as "D:\表.ods"
2. execute basic macro

Sub OpenFile_hyou_jp
  GlobalScope.BasicLibraries.LoadLibrary("ScriptForge")
 Dim session As Variant
  session = CreateScriptService("Session")
  session.RunApplication("D:\表.ods")
End Sub

Actual Results:
3. Error
The following script will also fail.
  session.RunApplication(ConvertToURL("D:\表.ods"))

Expected Results:
3. Open "D:\表.ods".


Reproducible: Always


User Profile Reset: No

Additional Info:
The script below works.
Sub OpenFile_hyou_jp_Shell
  Shell("soffice.exe", 1, "D:\表.ods")
End Sub

Reproducible with
Version: 24.8.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: f4ef5435df5560e6b6b061ce4053c71e2819bf51
CPU threads: 4; OS: Windows 10.0 Build 10240; UI render: Skia/Raster; VCL: win
Locale: ja-JP (ja_JP); UI: ja-JP
Calc: threaded
Comment 1 Werner Tietz 2024-06-05 05:37:48 UTC
Reproducible with:
```
Version: 24.2.3.2 (AARCH64) / LibreOffice Community
Build ID: 433d9c2ded56988e8a90e6b2e771ee4e6a5ab2ba
CPU threads: 4; OS: Linux 6.6; UI render: default; VCL: gtk3
Locale: de-DE (de_DE.UTF-8); UI: en-US
Flatpak
Calc: threaded
```

but NOT with:
```
Version: 7.4.7.2 / LibreOffice Community
Build ID: 40(Build:2)
CPU threads: 4; OS: Linux 6.6; UI render: default; VCL: gtk3
Locale: de-DE (de_DE.UTF-8); UI: de-DE
Debian package version: 4:7.4.7-1+deb12u2
Calc: threaded
```
btw.
!!It's best not to use ‘ScriptForge’ at all!!
Comment 2 Rafael Lima 2024-07-03 22:03:21 UTC
(In reply to Werner Tietz from comment #1)
> !!It's best not to use ‘ScriptForge’ at all!!

I don't understand this remark. ScriptForge does a lot of good things in a very practical manner.

As for the bug report itself...

(In reply to nobu from comment #0)
> Actual Results:
> 3. Error
> The following script will also fail.
>   session.RunApplication(ConvertToURL("D:\表.ods"))
> 
> Expected Results:
> 3. Open "D:\表.ods".

When you run ConvertToURL("D:\表.ods") the string becomes "%E8%A1%A8.ods" because of the character 表.

If you type the address directly, without passing it through ConvertToURL, it will work.

On my machine the following code worked:

Sub Foo
  GlobalScope.BasicLibraries.LoadLibrary("ScriptForge")
  Dim session As Variant
  session = CreateScriptService("Session")
  session.RunApplication("/home/rafael/Documents/表.docx")
End Sub
Comment 3 Werner Tietz 2024-07-04 10:36:50 UTC
(In reply to Rafael Lima from comment #2)
> (In reply to Werner Tietz from comment #1)
> > !!It's best not to use ‘ScriptForge’ at all!!
> 
> I don't understand this remark. ScriptForge does a lot of good things in a
> very practical manner.

Yes, I hear this nonsense again and again…… 

_____

sub foreign_unicode_file
   url = converttourl("/home/wertie/Documents/表.ods")
   doc = StarDesktop.loadComponentfromurl(  url  , 0,"_default", array())
end sub
____

…does the job, without any boilerplate
Comment 4 Jean-Pierre Ledure 2024-07-04 13:24:05 UTC
I could not reproduce the issue on

Version: 24.2.2.2 (X86_64) / LibreOffice Community
Build ID: d56cc158d8a96260b836f100ef4b4ef25d6f1a01
CPU threads: 6; OS: Linux 5.15; UI render: default; VCL: kf5 (cairo+xcb)
Locale: fr-BE (en_US.UTF-8); UI: en-US
Calc: threaded

Next code run as expected:

Sub OpenFile_hyou_jp
	GlobalScope.BasicLibraries.LoadLibrary("ScriptForge")
	Dim session As Variant
	session = CreateScriptService("Session")
	session.RunApplication("/home/jean-pierre/Documents/ScriptForge/Bugs/Bug 161405 (RunCommand CJK)/表.ods")
End Sub

The logic behind the scene is:
- check file existsnce otherwise abort
- run the Basic Shell statement (argument is in OS notation => no URL conversion)
- above fails because Shell() does not associate files with applications =>
   - convert to URL notation (file:///home/jean.../Bugs/Bug%20161405%20(RunCommand%20CJK)/%E8%A1%A8.ods)
   - run with the com.sun.star.system.SystemShellExecute service => OK
Comment 5 Jean-Pierre Ledure 2024-07-04 13:35:11 UTC
(In reply to Werner Tietz from comment #3)
> sub foreign_unicode_file
>    url = converttourl("/home/wertie/Documents/表.ods")
>    doc = StarDesktop.loadComponentfromurl(  url  , 0,"_default", array())
> end sub
> ____
> 
> …does the job, without any boilerplate

Of course, it does.
But I suspect that the goal is to open any file (containing CJK) with any suffix in its application. "ods" is there only as an example.
Comment 6 Werner Tietz 2024-07-04 16:54:54 UTC
(In reply to Jean-Pierre Ledure from comment #5)

> But I suspect that the goal is to open any file (containing CJK) with any
> suffix in its application. "ods" is there only as an example.

You may know what happens behind the scene of »session.RunApplication« … I dont so far, and I doubt that the average user knows it! 
It would not be so absurd to assume that the file path would be delegated to "stardesktop.loadComponentfromURL" ?

Again:
it still works in a normal Linux installation (LO7.4 ) but not with LO24.2 inside a **flatpak** container.

_______
btw.

with python I would use simply:
__________________
# the LO7.4 OS
import subprocess

subprocess.Popen(["soffice", "/home/wertie/Documents/表.ods"])
________________
# and from python inside the flatpak mentioned above
import subprocess

subprocess.Popen(["/app/libreoffice/program/soffice",
                  "/home/wertie/Documents/表.ods"])
_________________
Comment 7 Jean-Pierre Ledure 2024-07-05 13:03:13 UTC
(In reply to Werner Tietz from comment #6)
> You may know what happens behind the scene of »session.RunApplication« … I
> dont so far, and I doubt that the average user knows it! 
Indeed.
My only purpose here is to find the root cause of the bug. Is this an issue to find comments about internals of LO in bug reports ??
> 
> Again:
> it still works in a normal Linux installation (LO7.4 ) but not with LO24.2
> inside a **flatpak** container.
The original bug reporter uses Windows10.

I can confirm the bug under
Version: 24.2.4.2 (X86_64) / LibreOffice Community
Build ID: 51a6219feb6075d9a4c46691dcfe0cd9c4fff3c2
CPU threads: 6; OS: Windows 10.0 Build 19045; UI render: Skia/Raster; VCL: win
Locale: en-US (en_BE); UI: en-US
Calc: threaded

when executing next code:
 Sub OpenFile_hyou_jp
  GlobalScope.BasicLibraries.LoadLibrary("ScriptForge")
  Dim session As Variant
  session = CreateScriptService("Session")
  session.RunApplication("E:\ScriptForge\scriptforge\Tests\Bug161405\abc.ods")
 End Sub

The root cause is that next code - not involving ScriptForge - gives a "File not found" error:
 Sub OpenFile_hyou_jp2
  Set oShell = CreateUnoService("com.sun.star.system.SystemShellExecute")
  sCommand = ConvertToUrl("E:\ScriptForge\scriptforge\Tests\Bug161405\表.ods")
  oShell.execute(sCommand, "",  com.sun.star.system.SystemShellExecuteFlags.DEFAULTS)
 End Sub

It seems that the execute() method of the com.sun.star.system.SystemShellExecute service accepts both the OS and the URL notations in Linux and Windows. Execept in Windows when a non-ASCII character is present.
It works with filename = abc.ods, but not with àbc.ods and not with 表.ods.
Comment 8 Werner Tietz 2024-07-05 15:07:56 UTC
flatpak tells me »permission denied« with:
____
Sub OpenFile_hyou_jp2
  Set oShell = CreateUnoService("com.sun.star.system.SystemShellExecute")
  path = "/home/wertie/Documents/表.ods"
  oShell.execute( path, "",  com.sun.star.system.SystemShellExecuteFlags.DEFAULTS)
 End Sub
___
 but it works as intended when i give systemshell.execute the right arguments:
___
Sub OpenFile_hyou_jp3
  Set oShell = CreateUnoService("com.sun.star.system.SystemShellExecute")
  path = "/home/wertie/Documents/表.ods"
  command = "/app/libreoffice/program/soffice"
  oShell.execute(command, path,  com.sun.star.system.SystemShellExecuteFlags.DEFAULTS)
End Sub
Comment 9 Jean-Pierre Ledure 2024-07-09 13:25:34 UTC
(In reply to Jean-Pierre Ledure from comment #7)

> It seems that the execute() method of the
> com.sun.star.system.SystemShellExecute service accepts both the OS and the
> URL notations in Linux and Windows. Execept in Windows when a non-ASCII
> character is present.
> It works with filename = abc.ods, but not with àbc.ods and not with 表.ods.

After more tests under Linux, it appears that the execute() method of the
> com.sun.star.system.SystemShellExecute service works fine when the command argument is expressed in URL format.

This is the opposite of
 https://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1system_1_1XSystemShellExecute.html

"aCommand	Specifies the command to execute. This may be an executable file or a document which is registered with an application on a specific platform, so that the platform knows what application to launch for that document. If the command specifies a path to an executable, etc, this has to be a system specific path."

This is out of my scope.