Issue 125117 - SystemShellExecute call from BASIC doesn't pass arguments on Mac OSX but does on Windows
Summary: SystemShellExecute call from BASIC doesn't pass arguments on Mac OSX but does...
Alias: None
Product: App Dev
Classification: Unclassified
Component: api (show other issues)
Version: 4.1.0
Hardware: Mac Mac OS X, all
: P3 Normal
Target Milestone: ---
Assignee: AOO issues mailing list
QA Contact:
Keywords: needmoreinfo
Depends on:
Reported: 2014-06-18 19:37 UTC by Jeffrey Clemens
Modified: 2014-06-24 03:26 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Latest Confirmation in: ---
Developer Difficulty: ---

Spreadsheet with BASIC code attached (8.55 KB, application/vnd.oasis.opendocument.spreadsheet)
2014-06-19 03:44 UTC, Jeffrey Clemens
no flags Details
Writer document with a macro (9.75 KB, application/vnd.oasis.opendocument.text)
2014-06-19 05:39 UTC, Ariel Constenla-Haile
no flags Details

Note You need to log in before you can comment on or make changes to this issue.
Description Jeffrey Clemens 2014-06-18 19:37:07 UTC
I'm trying to call an external program from a BASIC macro using the SystemShellExecute UNO call.

oSvc = createUnoService("")
pathToExternal = "/appropriate/path/to/external/app"
args = "some arguments here"
oSvc.execute(convertToUrl(pathToExternal), args ,1)

On Windows this works perfectly (Assuming the pathToExternal variable was set to an actual windows pathname)

On MacOS, the external program is called, but it doesn't get the command line arguments.

I tested this by writing a simple python script which outputs the given command line arguments to a file, and calling the script from BASIC using the above code.  When I run it on Windows, the file contains whatever arguments were sent from the args variable.  When I run it on Mac, it only contains the path to the python script, with no arguments.

I assume this is a bug since it behaves differently on different implementations, and on Mac it doesn't work the way the documentation says it should.
Comment 1 Ariel Constenla-Haile 2014-06-19 00:47:35 UTC
IIRC on unix systems the argument string is passed as a single command, so it only works if you are passing only one argument.

Can you attach a document with a macro?
Can you run OpenOffice from the terminal and see the terminal output when you run the macro?

On Linux, for example, the following works:

Sub Main
	Dim oShell
	oShell =
End Sub

Sub Main
	Dim oShell
	oShell =
	oShell.execute("spd-say","Hello world!",
End Sub

But not the following:

Sub Main_2
	Dim oShell
	oShell =
	oShell.execute("spd-say","--voice-type ""female1"" ""Hello world""",
End Sub

on the terminal I get

spd-say: unrecognized option '--voice-type "female1" "Hello world"'
Unrecognized option
Comment 2 Jeffrey Clemens 2014-06-19 03:42:19 UTC
I don't think that's 100% of the problem.  

Even when I only have one argument, the program doesn't get it.  And when I run the macro after starting OpenOffice from the command line, I get nothing in the terminal window (no errors or anything else sent to stdout).  The program runs, but it doesn't get the single argument.

In the long term, I need to find a way to send multiple arguments to a program somehow, which I'll have to figure out, but right now I can't even send a single argument.

I've attached a spreadsheet with the BASIC code i'm using (or I will after I finish typing this).  It calls a program called 'test' which was just a simple python script that outputs sys.argv to stdout and to a file.  It tries to send a single argument "blah" which the python script should show as the first argument after the program name. The script shows only the program name (test).
Comment 3 Jeffrey Clemens 2014-06-19 03:44:50 UTC
Created attachment 83583 [details]
Spreadsheet with BASIC code attached

Basic code in Module1 calls an external program 'test' and attempts to send one argument to the program 'blah'.  The external program doesn't get the argument.
Comment 4 Ariel Constenla-Haile 2014-06-19 05:36:08 UTC
Does your script have a shebang? Did you make it executable?

Put the following in a file ~/, and make the file executable:

#!/usr/bin/env python
import sys
if __name__ == '__main__':
    if len(sys.argv) > 1:
        for s in sys.argv[1:]:
            print s

Here I see the following behavior:

a) converting the file to URL open the script for editing in XCode
b) using a system path instead of an URL, the script is executed (but with the bug mentioned above: there is no way to pass multiple commands
Comment 5 Ariel Constenla-Haile 2014-06-19 05:39:02 UTC
Created attachment 83584 [details]
Writer document with a macro

The macro assumes there is a Python shell script in ~/
Comment 6 Jeffrey Clemens 2014-06-23 01:32:50 UTC
Yes, I made it executable and had a shebang.  The script runs, and gives output.  The output only contains the name of the script, with no arguments showing up.  I'll try again using your script.  The only major difference is that I printed the list sys.argv, rather than iterating over it and printing its contents.  In my version, the list contains only one member, which is the path to the script itself.
Comment 7 Jeffrey Clemens 2014-06-24 03:26:24 UTC
I get slightly different results than you using your macro.

On all of the examples using the sScript variable, I get a runtime error:

Message: Undefined error: 0

On the one where you had trouble (Using the URL instead of the unix pathname), I get the same results as you, unless I remove the .py from both the filename and in the code, then it runs, but gets no arguments (this is how I was doing it before).

All of the examples using 'say' work the same as the way you describe.  

I also tried moving the script to /usr/bin (where 'say' is), and calling it with no path, but get the same error 0.

So my experience is different from yours.  When a system directory is used, I get an error.  Where a URL is used, the script runs, but doesn't get arguments.  Are we using different versions of os-x?  I have 10.8.5.  

Also, the inbuilt binaries seem to get arguments, but I can't get the script to get any arguments.