We will be migrating from Ask to Discourse on the first week of August, read the details here

Ask Your Question

How to NOT connect to a running instance [closed]

asked 2012-04-04 02:51:01 +0200

jimav gravatar image

updated 2013-07-24 20:39:09 +0200

bosyber gravatar image

I want to convert files from a script using command line options, for example:

   libreoffice --headless --invisible --convert-to csv file.xls

This works only if Libre Office is not currently running interactively.

For example, if localc was run (on an unrelated document), then the above shell command silently fails to have any effect.

I suspect the command connects to the pre-existing interactive instance. How can I prevent this, forcing the command to use an independently started instance?

(or any other way to make the command work reliably, whether or not LO is already running)

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2015-10-17 00:55:35.592238

1 Answer

Sort by » oldest newest most voted

answered 2012-04-04 20:39:39 +0200

hunteke gravatar image

updated 2012-07-14 07:55:23 +0200

This is unfortunately not directly possible thanks to Bug #37531.

The workaround is to run LibO with another profile. From that bug report then, comment 25 suggests using the not-so-well documented -env flag:

    libreoffice "-env:UserInstallation=file:///tmp/LibO_Conversion" --headless --invisible --convert-to csv file.xls

If security is a concern, note that LibO creates that directory with user-only permissions, and you can similarly tack on an rm (or the appropriate operating system variant) command:

    libreoffice [...] ; rm -rf /tmp/LibO_Conversion
edit flag offensive delete link more


Thanks, very useful. Small correction though, it should be:


bosyber gravatar imagebosyber ( 2013-07-24 20:21:41 +0200 )edit

Heh. It actually doesn't matter. The quotes are interpreted by the shell and are only required if there are "special characters" (e.g., spaces). They become more necessary if you want more robust behavior when interacting with unknown (user) input or variables, so using them as a matter of habit is just good practice. In this case, both methods will give LibreOffice the exact same string (with no quotes because the shell will remove them).

hunteke gravatar imagehunteke ( 2013-07-25 15:38:51 +0200 )edit

On several GNU/Linux systems /tmp is cleaned at each reboot, so you may not need to remove /tmp/LibO_Conversion

gerlos gravatar imagegerlos ( 2015-02-20 18:08:24 +0200 )edit

Even better is to create the temporary directory for every invocation, so that your script that calls libreoffice can be started multiple times in parallel, and starting out with a fresh slate every time:

tmpdir=`mktemp -d /tmp/libreoffice-XXXXXXXXXXXX`
trap "rm -rf $tmpdir" EXIT INT
libreoffice "-env:UserInstallation=file://$tmpdir" --headless --nolockcheck --convert-to pdf "$out"
bertd gravatar imagebertd ( 2015-10-29 11:29:22 +0200 )edit

Question Tools



Asked: 2012-04-04 02:51:01 +0200

Seen: 10,217 times

Last updated: Jul 14 '12