How to get the command line used to start LibreOffice?

LibreOffice can be started with parameters (arguments) from a command line (or a respective link). It must know the URL of a file to be opened in the simplest case (command by clicking). In less simple cases it has to execute commands it got by interpreting arguments.
How can user code access this information?

from subprocess import check_call

print(check_call(["soffice", "--help"]))

If I understand correctly, the question is to get the full command, together with the arguments, used to start the current process, not how to run another instance of LO to get its help.

Something similar to what e.g. Windows Task Manager provides, when the respective column is shown:

… or Sysinternals’ Process Explorer:

… but from a macro code.

May there be a misunderstanding?
My question is about getting the command line (the arguments) which was passed to the OS when LibO was started.

AI says :


:innocent:

Yes. (And a few more chartacters to satisfy the … what?)

In VBA, there is a Command function, that looks similar to what is asked (just omits the app executable name, only the arguments). But testing the function in MS Excel, that was launched like excel.exe path\to\file.xlsx, the result is an empty string.

In LibreOffice, Basic has nothing (neither an own function, nor the Command in VBASupport mode). It could be trivial to implement (we have functions like osl_getCommandArg).

Likewise, it could be interesting to access the current environment (knowing the working directory for instance) when a (BASIC) macro is run from the command-line.

Also, when the macro process ends, it would be useful to return the value to the command-line caller.

For the best of my knowledge, these can’t be done.

And won’t. The process exit code is unrelated to the macros. A macro is not the only thing happening in the process.

But you can use the standard output, and analyze that. Or maybe use files for communication.

Ok lets do the »soffice«-script half the task, edit the script and append a commandline like:

echo $@ > /some/path/to/last_soffice_params.txt
#todo: translate to windows syntax!

later in your basic you may open|read »/some/path/to/last_soffice_params.txt«

I maintain more than one user profile with a common install and as always the same user. This was the reason for what I was personally interested in an answer to my question, but factually just concerning the only commandline parameter I use on a regular basis:
-env:UserInstallation=
I have a workaround for this specific parameter. However, I thought and still think that the LibO API should support a service/property giving the full commandline.
A few decades ago when I still programmed now and then something I needed in Pascal (Delphi / Free) the running program always knew the command line, and I could use it to modify the working. (I don’t remember all the details.)

maybe digging into UserData
from ScriptForge.Platform service

ParamStr would be about what I would like to have access to in any running program, and I feel sure that programs written in C (C++) can easily do about the same.
As already told I have a workaround for the specific parameter without needing ScriptForge. I just rememberd this simplified workaround:

substSrv = CreateUNOService("com.sun.star.util.PathSubstitution")
userProfilePath = substsrv.getSubstituteVariableValue("$(user)")

The variable $(user) is a bit misleading insofar. It does NOT stand for the username, but for the profile path.

1 Like

Hello, colleagues!
Maybe it is worth implementing reading the command line arguments of LibreOffice call as a separate UNO service?
This information will be useful not only for LO Basic users.

1 Like