Skip to content

Commit 8e484ef

Browse files
committed
Redirect STDERR from help to /dev/null
On libreoffice > 4, the -h flag attempts to open the UI to display the help, in addition to writing it to stdout. This means that on Linux without X11 running, the output ends up looking like: Failed to open display LibreOffice 4.1.1.2 410m0(Build:2) This behavior can be avoided by using the `--headless` flag, but that flag isn't supported in older version of OpenOffice, causing an error there. Since Docsplit only looks at the first line of output it doesn't find the version string, causing it to assume it should use OpenOffice in the extract method. It then attempts to use the JOD convertor, which will fail on recent versions of LibreOffice. I believe this is the root cause of issue documentcloud#71 and should correct it.
1 parent 8086ad3 commit 8e484ef

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

lib/docsplit/pdf_extractor.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ def linux?
1919
# The first line of the help output holds the name and version number
2020
# of the office software to be used for extraction.
2121
def version_string
22-
versionstr = `#{office_executable} -h 2>&1`.split("\n").first
23-
if !!versionstr.match(/[0-9]*/)
24-
versionstr = `#{office_executable} --version`.split("\n").first
25-
end
26-
@@help ||= versionstr
22+
null = windows? ? "NUL" : "/dev/null"
23+
versionstr = `#{office_executable} -h 2>#{null}`.split("\n").first
24+
if !!versionstr.match(/[0-9]*/)
25+
versionstr = `#{office_executable} --version`.split("\n").first
26+
end
27+
@@help ||= versionstr
2728

2829
end
2930
def libre_office?

0 commit comments

Comments
 (0)